Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selectively revert or checkout changes to a file in Git?

Tags:

git

Is there a command that allows you to partially undo the changes to a file (or files) in the working directory?

Suppose you have edited a file a lot but you realize that you want to undo some of the changes back to the committed state, but not the other changes.

I'm envisioning an option for git checkout that works a lot like git add -p, i.e. it goes through the file hunk by hunk and asks if you want to keep it or not.

like image 338
1800 INFORMATION Avatar asked Apr 21 '09 09:04

1800 INFORMATION


People also ask

What is Revert selected changes?

Revert selected changes In the Changed Files pane, right-click the file that you want to revert and select Revert Selected Changes from the context menu. This results in a new commit that reverses the changes you want to undo.


1 Answers

With git version >= 1.7.1 I can

git checkout -p 

I am not sure when this feature was introduced.

like image 53
thisgeek Avatar answered Sep 20 '22 15:09

thisgeek