Git中的文件可以同时暂存和暂存吗? [英] Can a file be both staged and unstaged in Git?

查看:179
本文介绍了Git中的文件可以同时暂存和暂存吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编写另一个文件时,我编辑了 README.md ,然后运行 git add README.md 。在做一个git commit时,我发现 README.md 同时出现在要提交的更改和更改未提交进行提交中。

While working on another file, I edited README.md and then ran git add README.md. When doing a git commit, I see that README.md is both in the "Changes to be committed" and "Changes not staged for commit".

这有意义吗?在 .git 中的哪个位置可以查看该文件的授权状态?

Does this make sense? Where in .git could I look to see the authoritative state of this file?

# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   README.md
#       modified:   utils/arrterm
#
# 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:   README.md


推荐答案

这意味着您所做的部分更改是针对提交和部分

This means part of the changes you made are staged for commit and part are not.

如果您运行

You can check what is staged if you run

git diff --staged -- README.md

检查什么是运行

git diff -- README.md

大多数版本控制系统通常只存储两个状态之间的变化。 git的工作方式是,当你对一个文件进行多重修改时,你必须添加/标记每一个文件作为一组修改的一部分。当你使用 git add 时,这是自动完成的。

Most version control systems generally only store the changes between two states. The way git works, while you make multiple changes to a file, you will have to add/mark each of them to be part of one set of changes a.k.a a commit. When you use git add this is done automatically.

然而,它并不是你添加的唯一方法。个人变化(笨蛋)到你的指数。例如,您可以对同一文件进行多项更改,并在不同的提交中提交它们,或者仅对提交添加特定的更改。例如。要明确地向你的索引添加一些修改,而不是其他的修改,你可以通过使用 git add -p 来添加一些更改hunk(组)而不是整个变化列表本身。

However it is not the only way you add can all your individual changes(hunks) to your "index". You can for example make multiple changes to the same file and commit them in different commits or add only specific changes to a commit. E.g. to explicitly add some changes to your "index" but not others, you can do so by using git add -p to add only some "hunks" (groups) of the changes instead of the whole list of changes itself.

这里发生的是您在之前对 README.md 所做的更改暂存( git add )会在暂存中显示,并且在暂存 README.md 将显示为已停用,如上所述。

What has happened here is that the changes you made to README.md before staging ( git add) will show in staged and any changes you made after staging README.md will show as unstaged as you have got above.

这篇关于Git中的文件可以同时暂存和暂存吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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