0

I have a file on which I have made several uncommited modifications.

git diff somefile
 a
 b
+Added line
 c
 d
-Removed line
 f

How can I discard only some of these changes (say the removed line)?

git checkout somefile will discard all changes, and I would like a mechanism similar to git add -p that lets me select which hunks to keep and which hunks to discard.

Suzanne Soy
  • 3,027
  • 6
  • 38
  • 56
  • Indeed, although I did search prior to asking this question, I obviously used the wrong keywords. I'm requesting a close. – Suzanne Soy May 15 '14 at 11:28

2 Answers2

1

You could add the changes you want to keep to the index and then checkout the file to kill the unstaged changes. And then optionally reset it to move the changes from the index to the working copy.

Journey
  • 1,023
  • 1
  • 9
  • 12
0

Interactive staging should help. Although, personally, I find GUI clients like Sourcetree much more helpful in this case.

Max Yankov
  • 12,551
  • 12
  • 67
  • 135