代码之家  ›  专栏  ›  技术社区  ›  Esteis

Git:索引/暂存区域是否有符号引用?[副本]

git
  •  1
  • Esteis  · 技术社区  · 8 年前

    读后 Git pre-commit hook : changed/added files ,出现以下问题:

    如果我有一个同时包含暂存和未暂存更改的文件,如何在暂存后显示文件内容的预览?

    例子:

    echo "foo" >> file
    git add file
    echo "bar" >> file
    

    [previous contents of file]
    foo
    
    0 回复  |  直到 9 年前
        1
  •  115
  •   grawity_u1686    6 年前

    使用 :

    git show :file
    

    看见 gitrevisions (使用术语“阶段0”表示“正常”索引内容):

    :[<n>:]<path>, e.g. :0:README, :README
    

    冒号(可选后跟阶段号(0到3)和冒号(可选后跟路径)在给定路径的索引中命名blob对象。缺少的阶段编号(及其后面的冒号)将阶段0条目命名。在合并过程中,阶段1是公共祖先,阶段2是目标分支版本(通常是当前分支),阶段3是正在合并的分支的版本。

        2
  •  6
  •   Community Mohan Dere    9 年前

    最新消息: answer from grawity 有一个更整洁的解决方案

    这个食谱是从 jleedev's answer to another question

    git cat-file blob $(git ls-files -s file | awk '{print $2}')
    

    您可能需要创建一个 git alias 如果你要经常使用的话。

        3
  •  0
  •   Tollef Fog Heen    15 年前

    git grep -h --cached ^ -- file

        4
  •  -2
  •   Community Mohan Dere    9 年前

    看看这个问题的答案: How do I show the changes which have been staged?

    这个 --cached 选择是你想要的。