Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
901 views
in Technique[技术] by (71.8m points)

how to discard git local branch changes?

how to discard git local branch changes? eg, local branch with version: A->B->C Now I am on version A, and it has some changes conflict with latest version C. I want to discard local changes and pull the latest version C.

$ git pull

I will meet some error. and there are many files, so I don't need to do many times $ git co files

Is there any better way?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you have uncommitted changes that you want to discard, use this:

$ git reset --hard

which is equivalent to

$ git reset --hard HEAD

This removes all the local uncommitted changes. If you want to remove some offending commits from your local branch, try rewinding it:

$ git reset --hard HEAD^ #moves HEAD back by one commit

or e.g.

$ git reset --hard HEAD~3 #moves HEAD back by 3 commits

Use these with caution, as you won't be able to undo these operations. Once you're done cleaning up your local branch, use git pull to get the latest code.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...