To help in my knowledge of git so I can use it day to day, what is the difference between:
What are they and what do they do?
The git revert command is used for undoing changes to a repository's commit history. Other 'undo' commands like, git checkout and git reset , move the HEAD and branch ref pointers to a specified commit. Git revert also takes a specified commit, however, git revert does not move ref pointers to this commit.
James Gallagher - December 29, 2020. The git revert command will undo a commit so you can return a repository to the previous commit. Instead of deleting the commit, revert will create a new commit that will reverse the changes of a published commit. This preserves the initial commit as a part of the project's history.
Let's start with the Git command reset . Practically, you can think of it as a "rollback"—it points your local environment back to a previous commit. By "local environment," we mean your local repository, staging area, and working directory.
For this reason, git revert should be used to undo changes on a public branch, and git reset should be reserved for undoing changes on a private branch. You can also think of git revert as a tool for undoing committed changes, while git reset HEAD is for undoing uncommitted changes.
The terms revert and amend have a well defined meaning in Git. In contrast, rollback and undo do not have such a well defined meaning, and are open to interpretation.
...means creating (on the current branch) a new commit that applies the inverse changes that another commit introduced. It's the preferred approach for correcting a problem in a repo that has already been shared with others, because it doesn't involve any destruction (i.e. rewriting history).
To revert a commit identified by <commit>
, simply run
git revert <commit>
...means replacing the "current" commit by a new one that has the same parent(s); more details in How does git commit --amend work, exactly?
Be aware that
To amend a commit, make all the required changes and stage them, then run
git commit --amend
No need to specify any commit, here, because the last commit on the current branch is the one that will be amended. Your editor will then pop up, giving you the opportunity to modify the commit message.
...usually means discarding (or stashing) any local changes and resetting the branch to a commit (or simply checking out a commit, but that puts you in detached-HEAD state) prior to commit one where things started to get messed up. Use
git reset <commit-before-things-started-to-go-belly-up>
...can mean, depending on the context,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With