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

4
  • 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'. Commented Aug 30, 2016 at 7:12
  • 1
    Possible duplicate of git selective revert local changes from a file Commented Aug 30, 2016 at 7:12
  • @kometen did you read the question? They don't want to checkout/reset over all the changes in the file, just some. Commented Aug 30, 2016 at 7:13
  • @jonrsharpe Yes. And OP said some files were not added which I assumed was into git. Commented Aug 30, 2016 at 7:30

1 Answer 1

2

consider using

git checkout -p

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

Sign up to request clarification or add additional context in comments.

2 Comments

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
I'm sorry.I'm too lazy. git checkout -pandg - select a hunk to go to.This is great!!!!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.