Undo Uncommitted Changes
Before we start undoing things, let’s take a look at the status of our repository.
We have a tracked file and an untracked file that need to be changed. First, we’ll take care of
This changes all tracked files to match the most recent commit. Note that the
--hard flag is what actually updates the file. Running
git reset without any flags will simply unstage
index.html, leaving its contents as is. In either case,
git reset only operates on the working directory and the staging area, so our
git log history remains unchanged.
Next, let’s remove the
dummy.html file. Of course, we could manually delete it, but using Git to reset changes eliminates human errors when working with several files in large teams. Run the following command.
This will remove all untracked files. With
git statusshould now tell us that we have a “clean” working directory, meaning our project matches the most recent commit.
Be careful with
git reset and
git clean. Both operate on the working directory, not on the committed snapshots. Unlike
git revert, theypermanently undo changes, so make sure you really want to trash what you’re working on before you use them.
- July 15, 2015 @ 16:05:19 [Current Revision] by admin
- July 15, 2015 @ 16:05:19 by admin
No comments yet.