Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I reverse a specific hunk of a commit in git?

I'm wondering if there is a way to quickly reverse specific hunk of a commit.

I can generate a diff between two commits or HEAD to see the difference.

How do I reverse just one of those hunks (or better yet, a set of specific hunks)?

like image 304
dkinzer Avatar asked Nov 22 '10 17:11

dkinzer


People also ask

Can I go back to a specific commit in git?

An administrator can roll back the code repository to a previous commit -- that point-in-time copy -- in several ways, depending on the end goal. One approach is the git reset command. Before using this command, you must understand what git reset does.

How do I reverse a specific commit?

To undo changes associated with a specific commit, developers should use the git revert command. To undo every change that has happened since a given commit occurred, use git reset.


1 Answers

git checkout -p $REF -- path/to/file 

e.g.,

git checkout -p HEAD^ myfile 

Where $REF is a ref name or commit ID that specifies the commit you want to take the file state from. For example, to selectively revert changes made in the last commit, use HEAD^.

like image 188
cdhowie Avatar answered Oct 04 '22 10:10

cdhowie