user52151
user52151

Reputation: 63

git undo only changes to some files in a commit

What are best practices to accomplish this task:

I have commits:

A -- B -- C

Commit B consist of:

file1.java
file2.java
icon.png

I would like to undo changes to file1 and file2 but not to icon.png.

Upvotes: 4

Views: 124

Answers (1)

CB Bailey
CB Bailey

Reputation: 793027

You can stage a revert of commit B and then reset the image file before committing.

# Prepare a revert of B
git revert -n B

# Recover the current version of the image
git checkout HEAD -- icon.png

# Commit the "almost" reversion of B
git commit

Upvotes: 3

Related Questions