Git - why are double dashes needed when running a command on a deleted file?

前端 未结 3 1623
我在风中等你
我在风中等你 2021-01-02 05:35

Consider a git repository, where a file was once deleted.

git rm path/to/file
git commit -a -m\"testing\"

Ok, now I want to see the g

3条回答
  •  太阳男子
    2021-01-02 06:10

    git log could be used on files as well as on branches, tags and so on.

    Assume you have a folder called a/b/c, you'll get the commits for this folder using

    git log a/b/c
    

    That's fine.

    You could also have a branch called d/e/f. You'll get the commits for this branch using

    git log d/e/f
    

    That's fine too.

    Things start to get complicated if the item where git log should work on could not be clearly determined. If you're stupid and call your branch a/b/c too, git has no clue whose log shall be printed: that of the branch a/b/c or the log of your directory a/b/c? Therefore, you have to tell a bit more about the information you want to receive:

    • show the log of the branch a/b/c:
      git log a/b/c --
    • show the log of the folder a/b/c in the current branch:
      git log -- a/b/c
    • show the log of the folder a/b/c in the a/b/c branch:
      git log a/b/c -- a/b/c

    With the deleted file, you have a similar problem: there's neither a file called path/to/file present in the working copy, nor is there a branch called path/to/file. This is the reason why you have to specify what you want.

    Of course, git could know that there was a file called path/to/file 20.000 revisions ago but this would require (worst case) to search the entire history of your project whether such a file existed or not.

    By explicitly specifying the file path after the --, you tell git:

    search harder for that file, even if it takes hours


    Conclusion (answering your question):
    in your case, the -- is needed because otherwise git log would work slower in general.

提交回复
热议问题