How to revert uncommitted changes including files

2019-01-07 01:10发布

Is there a git command to revert all uncommitted changes in a working tree and index and to also remove newly created files and folders?

11条回答
可以哭但决不认输i
2楼-- · 2019-01-07 01:45

I think you can use the following command: git reset --hard

查看更多
家丑人穷心不美
3楼-- · 2019-01-07 01:45

Please note that there might still be files that won't seem to disappear - they might be unedited, but git might have marked them as being edited because of CRLF / LF changes. See if you've made some changes in .gitattributes recently.

In my case I've added CRLF settings into the .gitattributes file and all the files remained in the "modified files" list because of this. Changing the .gitattributes settings made them disappear.

查看更多
干净又极端
4楼-- · 2019-01-07 01:46

Use:

git reset HEAD filepath

For example:

git reset HEAD om211/src/META-INF/persistence.xml
查看更多
家丑人穷心不美
5楼-- · 2019-01-07 01:49

If you have an uncommitted change (its only in your working copy) that you wish to revert to the copy in your latest commit, do the following:

git checkout filename
查看更多
来,给爷笑一个
6楼-- · 2019-01-07 01:56

If you want to revert the changes only in current working directory, use

git checkout -- .

And before that, you can list the files that will be reverted without actually making any action, just to check what will happen, with:

git checkout --
查看更多
登录 后发表回答