Tutorial by Examples

Undoing a merge not yet pushed to a remote If you haven't yet pushed your merge to the remote repository then you can follow the same procedure as in undo the commit although there are some subtle differences. A reset is the simplest option as it will undo both the merge commit and any commits add...
If you screw up a rebase, one option to start again is to go back to the commit (pre rebase). You can do this using reflog (which has the history of everything you've done for the last 90 days - this can be configured): $ git reflog 4a5cbb3 HEAD@{0}: rebase finished: returning to refs/heads/foo 4...
To jump back to a previous commit, first find the commit's hash using git log. To temporarily jump back to that commit, detach your head with: git checkout 789abcd This places you at commit 789abcd. You can now make new commits on top of this old commit without affecting the branch your head is...
Undo changes to a file or directory in the working copy. git checkout -- file.txt Used over all file paths, recursively from the current directory, it will undo all changes in the working copy. git checkout -- . To only undo parts of the changes use --patch. You will be asked, for each chang...
Use git revert to revert existing commits, especially when those commits have been pushed to a remote repository. It records some new commits to reverse the effect of some earlier commits, which you can push safely without rewriting history. Don't use git push --force unless you wish to bring down ...
Assume you want to undo a dozen of commits and you want only some of them. git rebase -i <earlier SHA> -i puts rebase in "interactive mode". It starts off like the rebase discussed above, but before replaying any commits, it pauses and allows you to gently modify each commit as i...

Page 1 of 1