0

I changed something in a file, and did not use add or commit. Some part of my changes is not necessary, how can I only reset this part. (I know how to revert the whole file, but the file has many changes and only a little change must be reset. Resetting all the changes would be a nightmare)

For some reason I can only use the command line operation git

Chris Maes
  • 35,025
  • 12
  • 111
  • 136
weijia.wang
  • 2,088
  • 2
  • 18
  • 32
  • If you did not add the file to git you must manually revert. If you have the file in git you can go back to last commit point using 'git checkout filename'. – kometen Aug 30 '16 at 07:12
  • 1
    Possible duplicate of [git selective revert local changes from a file](http://stackoverflow.com/questions/1109069/git-selective-revert-local-changes-from-a-file) – jonrsharpe Aug 30 '16 at 07:12
  • @kometen did you read the question? They don't want to checkout/reset over all the changes in the file, just some. – jonrsharpe Aug 30 '16 at 07:13
  • @jonrsharpe Yes. And OP said some files were not added which I assumed was into git. – kometen Aug 30 '16 at 07:30

1 Answers1

2

consider using

git checkout -p

which allows you - for each patch of changes - to reset those changes.

Chris Maes
  • 35,025
  • 12
  • 111
  • 136
  • Thank you! it is very effective.(but if have many patch of changes, and only one patch I want reset,I have to deal with each one??OMG....just now,13 patch changes and only 1 patch need reset -.-!).No matter how,`git checkout -p` is very useful – weijia.wang Aug 30 '16 at 08:15
  • I'm sorry.I'm too lazy. `git checkout -p`and`g - select a hunk to go to`.This is great!!!!! – weijia.wang Aug 30 '16 at 08:43