From 99428c140b15becec4dd3a2c39b2e88fbc470893 Mon Sep 17 00:00:00 2001 From: Daniel McVicker <dmcvicke@terpmail.umd.edu> Date: Wed, 17 Jan 2018 11:46:48 -0500 Subject: [PATCH] Added 'undoing changes' section --- README | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/README b/README index 43c6a87..5093b7d 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 ---- -- GitLab