如何在进行本地提交后再次取消我的文件? [英] How can I unstage my files again after making a local commit?

查看:66
本文介绍了如何在进行本地提交后再次取消我的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经完成了以下命令:

pre $ g $ git add< foo.java>
git commit -m添加foo java

如何删除我的本地提交现在并使foo.java处于未分离状态?



如果我键入 git reset --hard ,我发现它会恢复我的修改foo.java到原来的。

HEAD ^ 应该做你想做的。在此之后,您将在索引中进行第一次更改(可以使用 git diff --cached >显示),并且您的最新更改不会暂存。 git status 会看起来像这样:

 #分支master 
#要提交的更改:
#(使用git reset HEAD< file> ...停用)

#修改:foo.java

#没有为commit提交更改:
#(使用git add< file> ...更新将提交的内容)
#(使用git checkout - < ; file> ...放弃工作目录中的更改)

#modified:foo.java

git add foo.java 并同时提交两个变更。




I have done the following command

git add <foo.java>
git commit -m "add the foo java"

How can I delete my local commit now and make foo.java in an unstaged state?

If I type git reset --hard, I found that it will revert my modify foo.java to the original one.

解决方案

git reset --soft HEAD^ should do what you want. After this, you'll have the first changes in the index (visible with git diff --cached), and your newest changes not staged. git status will then look like this:

# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   foo.java
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   foo.java
#

You can then do git add foo.java and commit both changes at once.

这篇关于如何在进行本地提交后再次取消我的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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