1

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.

JerkyTreats
  • 507
  • 6
  • 10

1 Answers1

1

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

Community
  • 1
  • 1
jhnphm
  • 66
  • 1
  • 3
  • Two main reasons I can't revert: a) they are fairly old commits and several pushes have been made since then and b) the files they committed are fairly important. I'll try the above suggestion. – JerkyTreats Mar 27 '15 at 16:05
  • Reverts shouldn't affect commits after the one being reverted, and they work by just create a new commit that reverses changes, so they shouldn't cause merge conflicts either - they don't revert a repo to the state before the reverted commit, they just undo the specified one. Having important files in that commit would be a dealbreaker for using revert though. Although, FYI, you can split up commits with rebase too, but rebasing history already pushed out is its own problem. – jhnphm Mar 27 '15 at 17:21