Git revert command is used to revert a particular commit.
Most of the times a commit is reverted when it is causing the regression during testing.
When git revert is done this itself results in a commit(author as a person who is reverting).
Usage is as follows:
git revert [options] <commit-ish>
or: git revert <subcommand>
--quit end revert or cherry-pick sequence
--continue resume revert or cherry-pick sequence
--abort cancel revert or cherry-pick sequence
-n, --no-commit don't automatically commit
-e, --edit edit the commit message
-s, --signoff add Signed-off-by:
-m, --mainline <n> parent number
--rerere-autoupdate update the index with reused conflict resolution if possible
--strategy <strategy> merge strategy
-X, --strategy-option <option> option for merge strategy
In simple terms to revert a particular commit git revert <commit-id>.
This internally creates a separate commit for reverting a previous commit.
Gir reset on the other hand is primarily used to reset the current HEAD to the specified state.
git reset is also very helpful in the following scenarios
1. When you have made some changes and you no longer wanted them to be committed you just wanted to go back to the older clean state
git reset --hard HEAD
2. When you wanted to go to two commits back
git reset --hard HEAD~2
3. When you are doing git pull. It might result in merging errors. In this case you might just want to get rid of the mess, then you can simply use
git reset --hard HEAD
4. You might have added a file to commit using git add abc.c
but later you realized you do not want to add then you can use the following
git reset -- abc.c
Most of the times a commit is reverted when it is causing the regression during testing.
When git revert is done this itself results in a commit(author as a person who is reverting).
Usage is as follows:
git revert [options] <commit-ish>
or: git revert <subcommand>
--quit end revert or cherry-pick sequence
--continue resume revert or cherry-pick sequence
--abort cancel revert or cherry-pick sequence
-n, --no-commit don't automatically commit
-e, --edit edit the commit message
-s, --signoff add Signed-off-by:
-m, --mainline <n> parent number
--rerere-autoupdate update the index with reused conflict resolution if possible
--strategy <strategy> merge strategy
-X, --strategy-option <option> option for merge strategy
In simple terms to revert a particular commit git revert <commit-id>.
This internally creates a separate commit for reverting a previous commit.
Gir reset on the other hand is primarily used to reset the current HEAD to the specified state.
git reset is also very helpful in the following scenarios
1. When you have made some changes and you no longer wanted them to be committed you just wanted to go back to the older clean state
git reset --hard HEAD
2. When you wanted to go to two commits back
git reset --hard HEAD~2
3. When you are doing git pull. It might result in merging errors. In this case you might just want to get rid of the mess, then you can simply use
git reset --hard HEAD
4. You might have added a file to commit using git add abc.c
but later you realized you do not want to add then you can use the following
git reset -- abc.c
No comments:
Post a Comment