Search code examples
gitgit-remotegit-branch

How to follow a file in git


I have deleted a file a couple of times in git, but it keeps turning up again as other branches are merged; I guess something like this:

                      o--  a topic  --o
                     /                 \
o-- [create file] --o-- [delete file] --o-- [file exists again]

It's especially hard for me to grasp what's going on since we work with git using "internal releases", i.e. I create release branches that I push, which our release manager pulls and merges down to master and I pull his master.

How can I find out where I (or someone else) deleted a file and what merge(s) that re-introduced the file? Thanks!


Solution

  • When you delete a file in a branch and then merge in another branch that does contain the file, the file remains deleted. Now, even if you deleted the file in the branch and merged this branch with the other, it will still be deleted.

    git merge: Removing files I want to keep!

    If some content was added to this file however, while merging, you will get the conflict and you will have to explicitly add this file and commit for it to come back into the branch where you deleted.


    There is --follow in git log

    --follow

    Continue listing the history of a file beyond renames (works only for a single file).
    

    But am not sure if that is what you are looking for here. You can also look into History Simplification in git log manual - http://git-scm.com/docs/git-log