你怎么能撤消最后的git add? [英] How can you undo the last git add?

查看:98
本文介绍了你怎么能撤消最后的git add?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能取消 git 中最后一个阶段(未提交)的更改?假设当前分支中有很多文件,有些是上演的,有些则不是。在某些时候,一些愚蠢的程序员不小心执行了:

  git add  - 。 

...而不是:

  git checkout  - 。 

这位程序员现在是否可以用一些神奇的 git 命令取消最后的更改?或者他应该在第一次尝试之前做出承诺?

。这将'取消'您上次提交后添加的所有文件。



如果您只想取消某些文件,请使用 git reset - <文件1> <文件2> < file n>



也可以通过使用 git reset - p


Is it possible to unstage the last staged (not committed) change in git? Suppose there were a lot of files in the current branch, some staged, some not. At some point, some foolish programmer accidentally executed:

git add -- .

...instead of:

git checkout -- .

Can this programmer now unstage his last changes with some magical git command? Or should he have committed before experimenting in the first place?

解决方案

You can use git reset. This will 'unstage' all the files you've added after your last commit.

If you want to unstage only some files, use git reset -- <file 1> <file 2> <file n>.

Also it's possible to unstage some of the changes in files by using git reset -p.

这篇关于你怎么能撤消最后的git add?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆