0

I have the following scenario on a Git branch.

  • Commit 1: file1, file2, file3 added.
  • Commit 2: file1, file3 changed.
  • Commit 3: file2 changed.
  • Commit 4: file3 changed.

I now have uncommitted changes in file2, and I would like to retrieve some changes made to file1 and file3 in commit 2, and then create a fifth commit? How can I do that?

jub0bs
  • 60,866
  • 25
  • 183
  • 186
UnSat
  • 1,347
  • 2
  • 14
  • 28
  • 1
    What if you rollback to commit 2 in a new branch? get the file content and then make changes in master branch and commit it. – Polynomial Proton Jan 19 '15 at 00:27
  • 4
    If I understand your question correctly, you want to use [interactive checkout](http://stackoverflow.com/questions/27336028/how-can-i-restore-only-a-few-lines-from-a-file-recorded-in-a-given-commit/27336339#27336339) on files 1 and 3, then stage everything and commit. – jub0bs Jan 19 '15 at 00:35

1 Answers1

0

In order to "revert your files", you should do:

git checkout HEAD~2 file1
git checkout HEAD~2 file3
Charkan
  • 831
  • 6
  • 12
  • The question is a bit unclear, but I think the OP wants to only *partially* restore `file1` and `file3` as they're stored in `commit2`. What you're suggesting would restore the *entire* files. – jub0bs Jan 21 '15 at 10:35