7

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!

Jonas Byström
  • 25,316
  • 23
  • 100
  • 147
  • 1
    could you come up with a simple scenario where your file reappears? I'm not managing to reproduce that. – Mat May 16 '11 at 15:05

2 Answers2

2

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

NickD
  • 5,937
  • 1
  • 21
  • 38
manojlds
  • 290,304
  • 63
  • 469
  • 417
  • Nope, sorry, that just shows me a couple of commits, but not the other stuff that's happened to the file. – Jonas Byström May 16 '11 at 14:55
  • Thanks for the edit, I'll accept your answer for the time being, but somehow the delete of the file was lost somewhere. The most probable cause I think is that I overwrote the branch(es) at some point when we changed release procedures. – Jonas Byström May 17 '11 at 05:22
  • Note that this is one big reason to avoid `git add .`, especially when merging: It's just too easy to just check in a deleted, conflicted file, or to add some conflict markers to your repo... – cmaster - reinstate monica Sep 07 '18 at 14:49
0

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.

fbstj
  • 1,684
  • 1
  • 16
  • 22
  • Unfortunately I'm unable to merge master into topic, since we're following an internal release procedure, but you're probably right about the cause of the reappearance of the file. I still don't know how to trace the file though. – Jonas Byström May 17 '11 at 05:03