简体   繁体   中英

How do I `hg revert -aC` in git?

Using Mercurial's hg revert -aC , or with long option names, hg revert --all --no-backup I can reset my working copy to head.

IE, which ever branch I'm on, it'll update the working copy to be the latest commit on that branch that the local repo contains.

In particular :

  • If I have commits in my local repository, it definitely won't discard those commits.
  • It will remove untracked files that are not ignored files.
  • It will leave ignored files alone.

I find this to be one of the most essential basic commands for working with a repo. I'll often make some exploratory changes to a few files and then want to abandon this to do begin real work from a pristine set.

How do I do that this git ?


This is logged as a duplicate of How do I use 'git reset --hard HEAD' to revert to a previous commit? . That question (and questions it links to) has answers that are a useful resource to answer this question. However, this question is specifically asking how a mercurial user should achieve part of their work flow using git instead.

To reset your working copy to head:

git reset --hard HEAD

To remove untracked files, but not ignored files:

git clean -f

WARNING: These commands will permanently revert all uncommitted changes and remove all untracked files!

However, used in this way, they will preserve any local commits that you have not yet pushed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM