Changes between Version 18 and Version 19 of WorkingWithGit


Ignore:
Timestamp:
Aug 20, 2016, 9:50:28 PM (8 years ago)
Author:
neverpanic (Clemens Lang)
Comment:

Document reverting

Legend:

Unmodified
Added
Removed
Modified
  • WorkingWithGit

    v18 v19  
    167167 1. Wrap the body at 72 characters
    168168 1. Use the body to explain what and why vs. how
     169
     170=== Reverting changes === #revert
     171Subversion has two methods for reverting changes: `svn revert`, which drops uncommitted local modifications and restores the committed state and `svn merge -c -12345` to undo committed changes.
     172
     173Due to Git's distributed nature, there are three stages that can be reverted:
     174
     175 - To drop uncommitted modifications, use `git checkout -- <filename>`. If you had already added the file to the index using `git add`, you have to unstage it first using `git reset HEAD <filename>`. `git status` prints these commands, so you don't have to remember them.
     176 - To undo a change that has already been committed and pushed, use `git revert <commitID>`. This will create a new commit that applies the inverse diff. Note that you still have to push this commit to publish it.
     177 - To throw away all changes that you have locally committed but not yet pushed, use `git reset --hard origin/master`. '''You will loose all your uncommitted and committed modifications.''' If that is not what you want, Git provides a variety of tools that allow you to change commits that you have not pushed yet (and theoretically also commits that have already been pushed, which will prevent you from pushing any changes again). Since this is an advanced topic it will not be covered here. As a pointer for further research, look for `git commit --amend` to change the topmost commit and `git rebase --interactive`, the so-called "interactive rebase", to change older commits.
    169178
    170179=== Repository split === #reposplit