How to return a folder to a specific commit by creating a patch

Here is my story for the "somefolder" folder

$ git log somefolder commit 89cd More changes to somefolder commit ef47a Updating somefolder and other stuff commit e095 Bugs fixed in somefolder 

I want to return some folder back to "Bugs fixed in some folder".

Since the second commit is related to changes outside of some folder, I do not want to return this commit.

I think the safest way would be to create a diff / patch between commit e095 and 89cd, which applies only to some folder, and then apply this patch. How can i do this?

+55
git
May 25 '11 at 2:54
source share
2 answers

You can use git checkout to update your repository to a specific state.

 git checkout e095 -- somefolder 

As for your question about creating diff, this will work too. Just generate diff to go from the current state to e095 :

 git diff 89cd..e095 -- somefolder 
+100
May 25 '11 at 3:10
source share

You can use the git reset to reset index, which will also include deleting files that were added to later commits ( git checkout does not do this at its discretion):

 git reset e095 -- somefolder 

However, git reset does not update the working copy, and the --hard option --hard not work with folders. So use git checkout so that the working copy is the same as the index:

 git checkout -- somefolder 

and then, if you also want to delete all the added files, you also need to do:

 git clean -fd somefolder 
+8
Feb 14 '17 at 10:46 on
source share



All Articles