Git: Undo local changes; git add . + git rm?

与世无争的帅哥 提交于 2019-12-03 02:24:37
manojlds

How do I undo these local changes, restoring them to the current versions in the repository?`

git reset --hard

(this will reset your index and working directory to HEAD)

Is there a git command that will git add . and git rm any files I've deleted locally, in one step?`

git add -u

(it wont add new files)

If you want to add new files, remove rm'ed files, and stage modifications to files:

git add -A

You can revert to your last valid commit (i.e. copy of the remote repo, in tour example) by issuing:

git reset --hard HEAD

Additionally, I suggest reading the useful http://progit.org/2011/07/11/reset.html page to better understand how reset work and what the index is, and why git add and git rm are separate commands.

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