JerkyTreats
JerkyTreats

Reputation: 526

Git: Restore all changed files from old commit

I've seen many answers here for restoring a single file, however I'm in a situation where a co-worker managed to blow away all the changes related to a specific commit.

Is there a way to checkout all the files that had changed in a specific commit, and push them forward to current master?

I've tried:

git checkout 3ed2aa8        //go to the commit with the change
git checkout -b getOldFiles //make it a legit branch
git rebase master           //get branch up to date
git checkout master         //go to local master
git merge getOldFiles       //in theory, get the changed files back

I'm not 100% sure, but I think it didn't achieve anything.

Upvotes: 1

Views: 411

Answers (1)

jhnphm
jhnphm

Reputation: 66

That won't do anything because 3ed2aa8 is an older commit and merges prioritize newer changes. You could do a rebase -i [commit prior to 3ed2aa8] and then reorder 3ed2aa8 to the front. Do this in a branch to make sure it does what you want.

git checkout -b fix
git rebase -i 3ed2aa8~ [Reorder list in text editor]
git checkout master
git merge fix 

Otherwise why not use git revert on the coworker's revision that blew away the commit?

git revert --no-commit [bad_rev1]
git revert --no-commit [bad_rev2]
git revert --no-commit [bad_rev...]
git commit

See Revert multiple git commits

Upvotes: 1

Related Questions