Back our Angular 4 Book on Kickstarter.

How can I revert a Git directory without affecting all changes?

I have been working on a specific code change with a client for about two weeks. This included about a dozen commits to the git repository before making a pull request. The client reviewed the pull request before merging, and requested I roll back a few changes. I had made these commit 8 commits ago, and from the dozens of files changed I only had to roll back two.

How do you do it?

I didn't see an obvious way to roll back just those files using SmartGit, my tool of choice, so I had to drop back to the command line. This did it:


git checkout SHA-Value /c/path/to/repo/root/path/to/subdirectory/with/rejected/changes

The SHA is the unique identifier for each commit. I opened up SmartGit, viewed a change log, found out which commit I changed these files, went to the commit before that, clicked 'details' and the SHA value is listed right there. You can also get the SHA value from GitHub if you prefer. Go into the Pull Request, and select commits. The value is in the table, to the right of the commit message.

The path to the directory is your local system path. I had to use the absolute path. Since I'm a Windows user that started with the C drive, drilled down into my project folder, to the repository. And then I drilled down deeper into the repository to find the specific subdirectory I wanted to revert. Reverting the subdirectory is easier than reverting all the files individually.

I executed the line inside of GitShell. Everything worked.

I found a bunch of posts covering this topic, but most of them confused me. Hopefully this helps someone. Let me know!

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
All Content Copyright 2005, 2006, 2007, 2008, 2009 Jeffry Houser. May not be reused without permission
BlogCFC was created by Raymond Camden. This blog is running version 5.9.2.002.