#git revert
git clone <https://url>
git log --oneline
9f58820 (HEAD -> main, origin/main, origin/HEAD) new file
2c76a55 first commit
echo "New demo file" > demo.txt
git add -A demo.txt
git commit -m "ticket 92"
git log --oneline
3ab8b74 (HEAD -> main) ticket 92
9f58820 (origin/main, origin/HEAD) new file
2c76a55 first commit
echo "adding more line" >> demo.txt
git commit -am "ticket 93"
git log --oneline
0f70f4f (HEAD -> main) ticket 93
3ab8b74 ticket 92
9f58820 (origin/main, origin/HEAD) new file
2c76a55 first commit
git show
OR
#using head
git show 0f70f4f
commit 0f70f4f177301f314ba83e409228bab6987156b4 (HEAD -> main)
Author: name <emailid@email.com>
Date: Wed Feb 23 01:25:47 2022 +0000
ticket 93
diff --git a/demo.txt b/demo.txt
index 3ad4fc4..746e199 100644
--- a/demo.txt
+++ b/demo.txt
@@ -1 +1,2 @@
New demo file
+adding more line
#git revert (always record a new copy)
git log --oneline
0f70f4f (HEAD -> main) ticket 93
3ab8b74 ticket 92
9f58820 (origin/main, origin/HEAD) new file
2c76a55 first commit
git revert 0f70f4f
[main c6e3374] Revert "ticket 93"
1 file changed, 1 deletion(-)
git status
On branch main
Your branch is ahead of 'origin/main' by 3 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
#redo the changes
git log --oneline
c6e3374 (HEAD -> main) Revert "ticket 93"
0f70f4f ticket 93
3ab8b74 ticket 92
9f58820 (origin/main, origin/HEAD) new file
2c76a55 first commit
cat demo.txt
New demo file
git revert c6e3374
[main 7e7621e] Revert "Revert "ticket 93""
1 file changed, 1 insertion(+)
cat demo.txt
New demo file
adding more line
git log --oneline
7e7621e (HEAD -> main) Revert "Revert "ticket 93""
c6e3374 Revert "ticket 93"
0f70f4f ticket 93
3ab8b74 ticket 92
9f58820 (origin/main, origin/HEAD) new file
2c76a55 first commit
#switching head using git checkout
git checkout 3ab8b74
Note: switching to '3ab8b74'.
...
git log --oneline
3ab8b74 (HEAD) ticket 92
9f58820 (origin/main, origin/HEAD) new file
2c76a55 first commit
git checkout main
Previous HEAD position was 3ab8b74 ticket 92
Switched to branch 'main'
Your branch is ahead of 'origin/main' by 3 commits.
(use "git push" to publish your local commits)
git log --oneline
7e7621e (HEAD -> main) Revert "Revert "ticket 93""
c6e3374 Revert "ticket 93"
0f70f4f ticket 93
3ab8b74 ticket 92
9f58820 (origin/main, origin/HEAD) new file
2c76a55 first commit
git log --oneline --graph
#graph view
* 7e7621e (HEAD -> main) Revert "Revert "ticket 93""
* c6e3374 Revert "ticket 93"
* 0f70f4f ticket 93
* 3ab8b74 ticket 92
* 9f58820 (origin/main, origin/HEAD) new file
* 2c76a55 first commit
#git reset
git log --oneline
7e7621e (HEAD -> main) Revert "Revert "ticket 93""
c6e3374 Revert "ticket 93"
0f70f4f ticket 93
3ab8b74 ticket 92
9f58820 (origin/main, origin/HEAD) new file
2c76a55 first commit
echo "This is foo.txt" > foo.txt
git add -A
git commit -m "version 1"
cat foo.txt
This is foo.txt
git log --oneline
b717ad4 (HEAD -> main) version 1
7e7621e Revert "Revert "ticket 93""
c6e3374 Revert "ticket 93"
0f70f4f ticket 93
3ab8b74 ticket 92
9f58820 (origin/main, origin/HEAD) new file
2c76a55 first commit
git reset HEAD~1
OR
git reset 7e7621e
#example for mixed
git log --oneline
7e7621e (HEAD -> main) Revert "Revert "ticket 93""
c6e3374 Revert "ticket 93"
0f70f4f ticket 93
3ab8b74 ticket 92
9f58820 (origin/main, origin/HEAD) new file
2c76a55 first commit
git status
On branch main
Your branch is ahead of 'origin/main' by 5 commits.
(use "git push" to publish your local commits)
Untracked files:
(use "git add <file>..." to include in what will be committed)
foo.txt
git reset command In the simplest terms:
--soft: uncommit changes, changes are left staged (index).
--mixed (default): uncommit + un stage changes, changes are left in the working tree.
--hard: uncommit + un stage + delete changes, nothing left.
No comments:
Post a Comment