Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing files from repository while merging makes them disappear

Tags:

git

git-merge

Here is a test repo demonstrating the problem: https://bitbucket.org/vektor330/bugtest

The sequence of events is this:

  1. Add some initial commit.
  2. Person A adds Conflict and source to develop.
  3. Person B adds Conflict to master.
  4. Person B merges develop into master, resolving conflict on Conflict using "mine" strategy, and removing source from the repository. This is now an empty commit, but can be commited and pushed back to remote.

The result is: source has disappeared completely from the repository. It appeared in 7dfa23e, there is a log of it appearing in the repo, and it quietly disappeared in 5080a24, without a single trace.

I would expect the commit 5080a24 to show "source removed", what is wrong with Git or my expectation?

like image 422
vektor Avatar asked Jul 08 '15 08:07

vektor


People also ask

Does merging delete files?

If you remove a file in one branch, the merge will remove it in the target branch too.


1 Answers

why this wouldn't show as the "content of the merge commit".

You can visualize the content of the merge commit by selecting the merge commit and each of the two parents in turn.

When you select (in SourceTree) the one from the develop branch (in addition of the merge commit), you clearly see that files_to_lose/source have been removed:

diff

Why does the commit itself not show the missing file?

Because in the case of a merge commit, there are two parents to compare against. SourceTree doesn't offer the diff against those two parents.

GitHub for Mac or Windows does, when you select only the merge commit:

GitHub for Windows

In short, this isn't about Git, just about the Git GUI that you are using.

like image 137
VonC Avatar answered Nov 03 '22 02:11

VonC