在git中暂存暂存文件? [英] Stages a staged file in git?

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

问题描述

我正在使用git管理我的项目。而且我对暂存文件时的git工作流感到困惑。

I'm using git to manage my project. And I'm confused with the workflow of git when staging a file.

如果我暂存了文件却忘记了提交,然后又修改了这些文件并再次暂存并提交了,怎么办?我可以回滚到第一阶段吗?

If I staged files and forgot commit and then I modify that files and stages again and commit, how can I roll back to first staged ?

推荐答案

Git内部-Git对象,每次更改文件内容并将其添加到缓存时,做一个:

As described in "Git Internals - Git Objects", each time you change the content of a file, and add it to the cache, you do a:

git hash-object -w test.txt

将其存储到存储的对象中。

That stores it to the object stored.

我只是添加了两个 git 连续一个文件,然后是:

I just did two git add consecutively for one file, followed by a:

C:\Users\VonC\prog\go\src\github.com\VonC\asciidocgo\.git>gfind -mmin -10 -print
.
./index
./objects/4f
./objects/4f/76d586459ec6ffc42257bb4c61d5422051cb10
./objects/61
./objects/61/24401794e7fee613f5a56593a0a8a059b2627a

(请注意 -mmin 参数查找自

我本可以在每次 git add 加上a后列出相同的sha1:

I could have listed those same sha1 after each git add with a:

git rev-parse :0:abstractNode_test.go

请参见 git rev -parse (和 code>做?):在索引中添加文件仅在阶段0中(合并期间使用阶段1、2和3记录,仍在索引中,共同祖先,源和目标版本)。

See git rev-parse (and "What does git rev-parse do?"): adding a file in the index is stage 0 only (stage 1, 2 and 3 are used during a merge to record, still in the index, the common ancestor, source and destination versions).

如果我存储了这两个Blob的内容:

If I store the content of those two blobs:

C:\Users\VonC\prog\go\src\github.com\VonC\asciidocgo>
git cat-file -p 4f76d586459ec6ffc42257bb4c61d5422051cb10 > a
git cat-file -p 6124401794e7fee613f5a56593a0a8a059b2627a > b

(请注意,我如何将' 4f / blob路径中的c>部分与路径的其余部分,以获得完整的sha1)

(Note how I concatenate the '4f/' part of the blob path with the rest of the path in order to obtain the full sha1)

a b 确实为我增加了我为同一文件添加的索引。

The diff between a and b does give me the additional bit I added to the index for that same file.

torek 也提到了在评论中


另一种(我认为更简单)的方法: git fsck --lost-找到

悬挂的blob对象出现在 .git / lost-found / other / 中,并且

您已经找到了所有的 cat-file -p-ed 。您在最后一个提交之前所做的前一个git add。

在我的案例中,只有一个出现:

You would indeed found all the previous git add you did before the final one which ended up committed.
In my case, only one showed up:

C:\Users\VonC\prog\go\src\github.com\VonC\asciidocgo\.git\lost-found\other>dir
 Volume in drive C has no label.
 Volume Serial Number is D866-48E1

 Directory of C:\Users\VonC\prog\go\src\github.com\VonC\asciidocgo\.git\lost-found\other

25/01/2014  17:31    <DIR>          .
25/01/2014  17:31    <DIR>          ..
25/01/2014  17:31            16 873 4f76d586459ec6ffc42257bb4c61d5422051cb10

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

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