0

I want to annotate/blame a file in a git repository on a revision using the following command:

git annotate [options] file [revision]

However, the file does not exist in the current repository anymore, but I know that the file was exist in 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

Is there simple way to annotate a deleted file without checking out the revision f80133a in this situation?

Justin Civi
  • 893
  • 1
  • 9
  • 15
  • Out of curiosity – why? – Matt Ball Dec 01 '15 at 02:35
  • Actually, I am tracing all the source files ever existed in the repository. revision f80133a fixed a bug of the file, and I want to know the author and the change. There are more similar cases, and I want to make it automatically. @MattBall – Justin Civi Dec 01 '15 at 02:43

2 Answers2

2
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

EDIT after OP's edit: without checking out, I don't think so, but I may be wrong.

EDIT2: I am wrong. You can also trick 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
Amadan
  • 191,408
  • 23
  • 240
  • 301
0

for the instance you can checkout to that commit to see the blame like

git checkout f80133a

after this you will reach that commit in a detached head state then do blame

git annotate [options] file 

and once you are done

git checkout your_prev_branch_name
ashishmohite
  • 1,120
  • 6
  • 14
  • Yes, this is a solution. However, I want to trace back all the files in the repository, this might too costly. If there is no better solution, I think I will adopt this one. Thanks ! – Justin Civi Dec 01 '15 at 02:39
  • in that case you can use some gui tool after doing checkout on ref – ashishmohite Dec 01 '15 at 02:40