git reset and revert
git reset
first create 3 commit
touch a.tx
t
ubuntu@LAPTOP-7E5UNQJ4:~/git-tutorial/devops-practice-project$ ls
a.txt
ubuntu@LAPTOP-7E5UNQJ4:~/git-tutorial/devops-practice-project$ git add a.
txt
ubuntu@LAPTOP-7E5UNQJ4:~/git-tutorial/devops-practice-project$ ls
a.txt
ubuntu@LAPTOP-7E5UNQJ4:~/git-tutorial/devops-practice-project$ ls -a
. .. .git a.txt
ubuntu@LAPTOP-7E5UNQJ4:~/git-tutorial/devops-practice-project$ git add a.
txt
ubuntu@LAPTOP-7E5UNQJ4:~/git-tutorial/devops-practice-project$ git commit
-m "commit 1"
git log
commit 776b908b94ebf38818b6b5c0f083bb19beef9190 (HEAD -> master)
Author: Anas <ubuntu@LAPTOP-7E5UNQJ4>
Date: Mon Jan 27 01:42:09 2025 +0530
commit 1
ubuntu@LAPTOP-7E5UNQJ4:~/git-tutorial/devops-practice-project$ touch b.tx
t
ubuntu@LAPTOP-7E5UNQJ4:~/git-tutorial/devops-practice-project$ git add b.
txt
ubuntu@LAPTOP-7E5UNQJ4:~/git-tutorial/devops-practice-project$ git commit
-m "commit 2"
[master 5ab41be] commit 2
touch c.txt
ubuntu@LAPTOP-7E5UNQJ4:~/git-tutorial/devops-practice-project$ git add c.
txt
ubuntu@LAPTOP-7E5UNQJ4:~/git-tutorial/devops-practice-project$ git commit
-m "commit 3"
[master 97338d2] commit 3
ubuntu@LAPTOP-7E5UNQJ4:~/git-tutorial/devops-practice-project$ git log
commit 97338d2e29871ed4741a724b5a8d8d1ad2abcba2 (HEAD -> master)
Author: Anas <ubuntu@LAPTOP-7E5UNQJ4>
Date: Mon Jan 27 02:03:42 2025 +0530
commit 3
commit 5ab41bed845df69771cd2587b18d76d66d8d9b3b
Author: Anas <ubuntu@LAPTOP-7E5UNQJ4>
Date: Mon Jan 27 02:01:19 2025 +0530
commit 2
commit 776b908b94ebf38818b6b5c0f083bb19beef9190
Author: Anas <ubuntu@LAPTOP-7E5UNQJ4>
Date: Mon Jan 27 01:42:09 2025 +0530
commit 1
now do git reset mixed
git reset --mixed HEAD~1
if i do git log
git log
commit 5ab41bed845df69771cd2587b18d76d66d8d9b3b (HEAD -> master)
Author: Anas <ubuntu@LAPTOP-7E5UNQJ4>
Date: Mon Jan 27 02:01:19 2025 +0530
commit 2
commit 776b908b94ebf38818b6b5c0f083bb19beef9190
Author: Anas <ubuntu@LAPTOP-7E5UNQJ4>
Date: Mon Jan 27 01:42:09 2025 +0530
commit 1
if i do git status
ubuntu@LAPTOP-7E5UNQJ4:~/git-tutorial/devops-practice-project$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
c.txt
nothing added to commit but untracked files present (use "git add" to track)
it also remove from staging area work space se remove nii hua commit se ho gya remove
so now add git add and commit of c.txt
ubuntu@LAPTOP-7E5UNQJ4:~/git-tutorial/devops-practice-project$ ls
a.txt b.txt c.txt
ubuntu@LAPTOP-7E5UNQJ4:~/git-tutorial/devops-practice-project$ git add c.
txt
ubuntu@LAPTOP-7E5UNQJ4:~/git-tutorial/devops-practice-project$ git commit
-m "commit 3"
[master 5e8a348] commit 3
now do git log
ubuntu@LAPTOP-7E5UNQJ4:~/git-tutorial/devops-practice-project$ git log
commit 5e8a348ce4e1545f2080c717d8251f0727ea58f1 (HEAD -> master)
Author: Anas <ubuntu@LAPTOP-7E5UNQJ4>
Date: Mon Jan 27 02:08:49 2025 +0530
commit 3
commit 5ab41bed845df69771cd2587b18d76d66d8d9b3b
Author: Anas <ubuntu@LAPTOP-7E5UNQJ4>
Date: Mon Jan 27 02:01:19 2025 +0530
commit 2
commit 776b908b94ebf38818b6b5c0f083bb19beef9190
Author: Anas <ubuntu@LAPTOP-7E5UNQJ4>
Date: Mon Jan 27 01:42:09 2025 +0530
commit 1
now do git soft reset'
git reset
--soft HEAD ~1
commit area se remove hoga
staging area se remove nii hua
workspace me bhi h
now if we do again commit to new commmit id bnega upar vale se alg
now do hard reset
hard reset se sb udh jayga
ubuntu@LAPTOP-7E5UNQJ4:~/git-tutorial/devops-practice-project$
git reset--hard HEAD~1
HEAD is now at 5ab41be commit 2
ubuntu@LAPTOP-7E5UNQJ4:~/git-tutorial/devops-practice-project$ ls
a.txt b.txt
git status
On branch master
nothing to commit, working tree clean
ubuntu@LAPTOP-7E5UNQJ4:~/git-tutorial/devops-practice-project$
git revert
git log
commit 8fb63d045704243ef4f4bb6e808c95fd66db2220 (HEAD -> master)
Author: Anas <ubuntu@LAPTOP-7E5UNQJ4>
Date: Mon Jan 27 02:51:04 2025 +0530
commit 3
commit 5ab41bed845df69771cd2587b18d76d66d8d9b3b
Author: Anas <ubuntu@LAPTOP-7E5UNQJ4>
Date: Mon Jan 27 02:01:19 2025 +0530
commit 2
commit 776b908b94ebf38818b6b5c0f083bb19beef9190
Author: Anas <ubuntu@LAPTOP-7E5UNQJ4>
Date: Mon Jan 27 01:42:09 2025 +0530
commit 1
now do git revert of commit id 2
git revert 5ab41bed845df69771cd2587b18d76d66d8d9b3b
[master 77ec8b1] Revert "commit 2"
Committer: Anas <ubuntu@LAPTOP-7E5UNQJ4>
if we do git log we see it create 1 more commit id
ubuntu@LAPTOP-7E5UNQJ4:~/git-tutorial/devops-practice-project$ git log
commit 77ec8b1d0c9966cc682a16afec6aaa7d47a3d549 (HEAD -> master)
Author: Anas <ubuntu@LAPTOP-7E5UNQJ4>
Date: Mon Jan 27 02:51:51 2025 +0530
Revert "commit 2"
This reverts commit 5ab41bed845df69771cd2587b18d76d66d8d9b3b.
commit 8fb63d045704243ef4f4bb6e808c95fd66db2220
Author: Anas <ubuntu@LAPTOP-7E5UNQJ4>
Date: Mon Jan 27 02:51:04 2025 +0530
commit 3
commit 5ab41bed845df69771cd2587b18d76d66d8d9b3b
Author: Anas <ubuntu@LAPTOP-7E5UNQJ4>
Date: Mon Jan 27 02:01:19 2025 +0530
commit 2
commit 776b908b94ebf38818b6b5c0f083bb19beef9190
Author: Anas <ubuntu@LAPTOP-7E5UNQJ4>
Date: Mon Jan 27 01:42:09 2025 +0530
commit 1
now we do ls so b.txt file removed
ubuntu@LAPTOP-7E5UNQJ4:~/git-tutorial/devops-practice-project$ ls
a.txt c.txt
if we do git show - it give ki ek file delete ki h
git show 77ec8b1d0c9966cc682a16afec6aaa7d47a3d549
commit 77ec8b1d0c9966cc682a16afec6aaa7d47a3d549 (HEAD -> master)
Author: Anas <ubuntu@LAPTOP-7E5UNQJ4>
Date: Mon Jan 27 02:51:51 2025 +0530
Revert "commit 2"
This reverts commit 5ab41bed845df69771cd2587b18d76d66d8d9b3b.
diff --git a/b.txt b/b.txt
deleted file mode 100644
index e69de29..0000000