如何在git中注释已删除的文件?

时间:2015-12-01 02:31:15

标签: git annotate

我想使用以下命令在修订版的git存储库中注释/归咎文件:

git annotate [options] file [revision]

但是,该文件不再存在于当前存储库中,但我知道该文件存在于修订版f80133a中。

git annotate java/org/apache/catalina/valves/CometConnectionManagerValve.java f80133a
fatal: cannot stat path 'java/org/apache/catalina/valves/CometConnectionManagerValve.java': No such file or directory

在这种情况下,是否有简单的方法来注释已删除的文件而不检查修订版f80133a?

2 个答案:

答案 0 :(得分:1)

git stash                # if you have pending changes
git checkout f80133a
git annotate java/org/apache/catalina/valves/CometConnectionManagerValve.java > annotation.txt
git checkout master      # or develop, or wherever you were
git stash pop            # if stashed
在OP编辑后编辑:没有退房,我不这么认为,但我可能错了。

EDIT2:我错了。你也可以欺骗git:

touch java/org/apache/catalina/valves/CometConnectionManagerValve.java
git annotate java/org/apache/catalina/valves/CometConnectionManagerValve.java f80133a
rm java/org/apache/catalina/valves/CometConnectionManagerValve.java

答案 1 :(得分:0)

对于实例,您可以签出该提交以查看责任,如

git checkout f80133a

在此之后,您将以分离头状态到达该提交 然后责备

git annotate [options] file 

一旦你完成了

git checkout your_prev_branch_name