Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

Git confusion - how to revert local changes to latest remote push?

I have a local git repository, but things get wrong and complicated and I simply want to overwrite all the files in my local directory with the latest version of what is on the remote repository. This would be like a clone, but for an already setup local git repository.

For example: if use git pull, then I don't get locally deleted folders back from the remote.

Is it checkout that I must use? But how to tell it to retrieve the files from a remote (and not from the stage) and overwrite all?

question from:https://stackoverflow.com/questions/12845507/git-confusion-how-to-revert-local-changes-to-latest-remote-push

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

1 Answer

0 votes
by (71.8m points)

You probably want to use git reset. Assuming you have done a git fetch recently, the following will discard everything in your local and reset it to the point you specify as the final argument (in this case the current HEAD of the origin/master remote tracking branch):

$ git reset --hard origin/master

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...