diff --git a/README b/README index 43c6a87b74e2fd5a086b31c97d96acb5b2d93795..5093b7d5f4ee53c3c74348e4ae9a6308741aec2f 100644 --- a/README +++ b/README @@ -706,6 +706,38 @@ dealing with conflicts Save the log message file, and exit. We now have completed our merge! See what the log shows. +undoing changes +--------------- + + When things stop working, sometimes starting over is easier than trying to + find and fix the error. One of the nice features of git is that you can + "go back" to any of your commits. For example, if you want to reset your + repository to the state it was in when you last committed, run: + + git reset --hard HEAD + + More generally, you can restore your local repository to ANY previous commit. + To do this, find the commit hash of the commit you want to restore (e.g. via + git log) and run: + + git reset --hard <hash> + + However, since this discards changes to all files in the repository, it's not + ideal if only one or two files are broken, and the rest have changes you + want to keep. Fortunately, git has a way to restore individual files. To + reset file1, run: + + git checkout [<commit hash>] -- file1 + + (Note: the 'commit hash' argument is optional. If you omit it, git will + default to using the previous commit) + + IMPORTANT: The ability to restore old versions can be incredibly useful, + but only if you make regular commits. There WILL be a time when you'll need + to reset your repository -- if your last working commit was five minutes + ago, this will be a minor setback; if it was five hours ago, you'll be much + less happy. Remember: commit early, commit often! + gitk ----