Shaun Luttin
Shaun Luttin

Reputation: 141622

Recover part of a file in an old commit

Here's the scenario.

commit -am "1 create book.txt
commit -am "2 add content to book.txt"
commit -am "3 delete content from book.txt and replace it new content"

Now we want to bring back the content that we added in commit 2 and deleted in commit 3. We've tried to merge commit 2 with commit 3, but this doesn't work. Of course we can just checkout commit 2, copy the content that we deleted, and then paste in again after we checkout commit 3. Is there a way to do this, though, with something similar to merge, rebase, or patch? The end result should have both the content that we added in commit 2 and the content that we added in commit 3.

Upvotes: 0

Views: 24

Answers (1)

SLaks
SLaks

Reputation: 887807

That's exactly what cherry-pick is for.

Use git cherry-pick commit-2 to replay that commit on top of the current state.

Upvotes: 2

Related Questions