LeG*_*GEC 5 git git-index git-reflog
我手头没有特定的问题,但是在过去的某些情况下,我偶然遇到了意外破坏索引的情况,希望我可以返回给定文件的先前状态,该状态在某个时刻被索引了。
一些示例情况是:
$ git add <file>
# find out that I already had an indexed version of <file>,
# and that for some reason I shouldn't have added the extra modifications
$ git stash pop
# find out afterwards that I have a mix of "the index I had"
# and "the index in the stash"
$ git stash
# with an active index, which is now mixed with the state of the working tree
$ git reset <typo>
# accidentally resetting the wrong file, or the whole directory
Run Code Online (Sandbox Code Playgroud)
人们可以诉诸挖通git fsck --full --unreachable --no-reflog(如建议在这里),我想知道是否有这样做更方便的方式。
题 :
索引是否有某种引用?
引用日志包含引用条目...而不是索引。
但是,也许工作流程调整就是答案……(这对我来说)。
如果处理的事情需要超过 5-10 分钟,请即提交(并在推送之前进行清理)。否则,就按你的方式进行。
太棒index了...我整天都用它!但只有当我知道我将在一两分钟内提交(基本上是原子工作流程操作)时,我才会真正使用它。这是因为我害怕我会做一些愚蠢的事情并毁掉我的索引。
当我工作时,每当我达到一个小里程碑时,我都会做出一个私人承诺,除非我有机会先进行一些清理工作,否则通常不会推送该承诺。当我致力于解决特定问题时,我会不断做出承诺,通常会进行修改。
然后,一旦我实际上达到了一个稳定点,我想创建一个公共提交,我就会将(如果需要)所有的小 wip 提交压缩在一起,给出一个很好的提交消息并推送。
如果需要的话,这提供了在我的转发日志中创建小面包屑的巨大优势。
这是我的工作流程:
# start work
git checkout -b featurea
# work
vim file.txt
# reach a little milestone
git commit -a -m "working on feature..."
# work some more
vim file.txt
# reach another little milestone
git commit -a --reuse-message=HEAD --amend
# work some more
vim file.txt
# another little milestone...
git commit -a --reuse-message=HEAD --amend
# finishing touches...
vim file.txt
# ok, done now, put everything back in working dir so I can review
git reset HEAD~
# decide what goes in this commit
# perhaps use `git add -p`
git add file.txt
# give a nice commit message (use editor)
git commit
# now merge to master and push with confidence!
Run Code Online (Sandbox Code Playgroud)
这可能看起来需要大量打字,但是如果您擅长在外壳上飞行(利用set -o emacs或是set -o vi一个好方法),那么这种方法几乎变得即时。
如果我正在做的事情确实是一个非常快速的修复,我通常只会使用“即用即用”的方法,但任何比这更长的方法,我都需要安全地填充我的引用日志。
| 归档时间: |
|
| 查看次数: |
297 次 |
| 最近记录: |