Question

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!

Was it helpful?

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

OTHER TIPS

What is happening is that when you merge the topic branch back in, it contains a blob/object which doesn't exist in the main branch, so the merge will create a file containing the state it was in in the topic branch. To stop this behaviour, I would merge the other way (merge main into topic) or rebase topic onto main. The problem comes if you change the file in topic then it will try to apply the changes to main resulting in the recreation of the file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top