git checkout all the files

坚强是说给别人听的谎言 提交于 2019-12-18 09:57:01

问题


How can I get rid of all the changes in all the files of my repository?

Say I am in a branch and I did some changes. git status returns a set of files in the "Changes not staged for commit" and I notice I would like to get rid of all of these changes in all the files. How can I do this with a single command?

I know I can do the following to checkout just one file:

git checkout -- <file>

I noticed that git checkout -- alone returns the list of all uncommited files. However, I cannot find a way to checkout all of them, something like git checkout --all.

I checked man git checkout and could not find anything. Also I saw Git: Checkout all files except one and tried git checkout . and did not work either.

Would I have to do it programmatically, by looping through the git checkout -- output?


回答1:


If you are at the root of your working directory, you can do git checkout -- . to check-out all files in the current HEAD and replace your local files.

You can also do git reset --hard to reset your working directory and replace all changes (including the index).




回答2:


Other way which I found useful is:

git checkout <wildcard> 

Example:

git checkout *.html

More generally:

git checkout <branch> <filename/wildcard>


来源:https://stackoverflow.com/questions/29007821/git-checkout-all-the-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!