Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 457
Jonas Byström Avatar asked May 16 '11 14:05

Jonas Byström


People also ask

How does git keep track of files?

Indexing. For every tracked file, Git records information such as its size, creation time and last modification time in a file known as the index. To determine whether a file has changed, Git compares its current stats with those cached in the index. If they match, then Git can skip reading the file again.

How can I track untracked files?

Just type git status in the command prompt. This will now list which files are staged, unstaged, and untracked.


1 Answers

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

like image 162
manojlds Avatar answered Oct 05 '22 04:10

manojlds