clemens
clemens

Reputation: 115

See past merge conflicts in GIT

How can anyone check in a git-repository what commits were made because of merge conflicts?

What happened is, that I'd like to find out, in a specific branch with multiple people working on it, if a specific commit back in the past was because of a merge conflict.

I use TortoiseGit for analysis or the git bash.

Upvotes: 1

Views: 1042

Answers (1)

IMSoP
IMSoP

Reputation: 97948

The way git stores history means that there isn't really an answer to this question. To explain:

  • A commit in git stores a snapshot of the entire repository, not a record of the changes in that commit (the storage of that snapshot is optimised, but that's not relevant to the question).
  • A standard commit has a single parent; if you ask for the changes introduced in a commit, git just compares its snapshot with the snapshot on its parent.
  • A merge commit has two or more parents - one from each of the branches involved in the merge. Theoretically, there is no "main" parent; although in practice, the first parent is generally the branch you had checked out, and the second (and any further) parents are the arguments you passed to "git merge" or "git pull".
  • When you ask git for the changes introduced in a merge commit, it has to compare it with something, such as one of the two parents.
  • When you resolve a merge conflict, you generally do so before committing the result. So the conflicted version is never recorded as a separate commit, and so just isn't there to compare against later.
  • Note that even without a conflict, it's possible for a merge commit to contain code that didn't come from either of its parents - it is, as far as git is concerned, just another snapshot of the repository.

The closest you could come would be to replay the merge, and compare the result of that with the merge commit. However, different tools and options will use different strategies to perform the merge, so there is no guarantee that the reply would actually reconstruct what the developer saw when they performed the original merge.

Upvotes: 4

Related Questions