2
  • In my commits history I see I made a commit where I added few lines to a file Masterlist/Index.cshtml.
  • Nobody else edited the file since and 3 months before.
  • After the commit there were some merges with conflicts which were resolved and after that there is a merge without conflict which has these lines from the file removed.
  • In file history there are no changes except the one 3 months old...

Commit where I added the lines: enter image description here

Merge which removed it: enter image description here

git log --graph --full-history -- ABC/Views/Masterlist/Index.cshtml produced this: enter image description here

git log -S"-webkit-transform: translateY(-100%) rotate(90deg); /* Safari */" -c produced this: enter image description here

My questions:

  1. How is it possible that the added lines were erased? What could go wrong?
  2. How to prevent this from happening?
  3. Why there are no entries in file history?

We are using Source tree or Visual studio when working with git.

chriemmy
  • 119
  • 11
  • 1
    I guess you need to show some graph with "what happend when and where". – Christoph May 29 '18 at 07:25
  • What does `git log --graph --full-history -- ` show? – max630 May 29 '18 at 07:44
  • 1
    If you know some key words of the removed lines, you could try `git log -S"keywords" -c` to find which commits have the diff including the keywords. – ElpieKay May 29 '18 at 07:50
  • 1
    I’d wager $5 that somebody did a `git merge -sours`. – Edward Thomson May 29 '18 at 08:42
  • @Christoph I added the screens – chriemmy May 29 '18 at 08:48
  • @EdwardThomson How would you check if your guess is correct? – Christoph May 29 '18 at 09:28
  • @max630 Output of the command is in the edited question – chriemmy May 29 '18 at 10:06
  • @ElpieKay I run the command. There's no change in the file other than in commit 2f3f2a2. Then there are mentioned 3505b40, 4246a23 and bad9e13 without any changes. I can post the output. I may have misinterpreted something. I'm not familiar with git commands too much. – chriemmy May 29 '18 at 10:14
  • @,chriemmy to show the diff of a merge commit, add the option `-c` to `git show `. – ElpieKay May 29 '18 at 10:16
  • @ElpieKay I tried `git log -S"-webkit-transform: translateY(-100%) rotate(90deg); /* Safari */" -c` - see edited question. `git show bad9e1387df46c6f1fc0df32d757d0b4ed6ad316 -c` displayed no diffs... – chriemmy May 29 '18 at 10:22
  • @EdwardThomson I'm not familiar with git commands, what does that do? How can I check if that's what caused this? – chriemmy May 29 '18 at 10:24
  • Thanks, and one more try: what does `git diff 3505b4..4246a2` show? – max630 May 29 '18 at 12:24
  • `--strategy=ours`: [docs](https://git-scm.com/docs/git-merge#git-merge-ours), [SO explanation](https://stackoverflow.com/a/366940/2303202) – max630 May 29 '18 at 12:27
  • 1
    @max630 I understand that `strategy=ours` is used to disregard one side of merge completely ... most probably not my problem, because other files were merged fine. `git diff 3505b4..4246a2` shows nothing much ... differences in other files but not in my file. – chriemmy May 29 '18 at 13:41
  • You could use a git bisect to find where the code was changed. Git wouldn’t remove it unless someone committed that removal. – evolutionxbox May 29 '18 at 19:15

1 Answers1

1

It looks like the wrong merge is 4246a2, which failed to get the change from 2f3f2a.

I am very sure (trusting the conflicted files list in the commit message, and leaving 1% for some rename detection went crazy, though I don't see how it could happen without removing the file), that if you check out the 3505b4 commit and merge 2f3f2a, reproducing the merge with conflict, you will have file ABC/Views/Masterlist/Index.cshtml cleanly staged with your change without conflict.

If it confirms, something should have went wrong in the conflict resolution. I think you should revisit the process of conflict resolution with that person. I can imagine 2 options why it happened:

  1. The tool/process which resolved the conflict did something wrong.

  2. The developer who performed the 4246a2 merge, used -sours and manually brought the other parent's changes, and somehow skipped that file's changes.

max630
  • 8,762
  • 3
  • 30
  • 55
  • You are right! The change in Masterlist/Index is visible when reproducing the merge. Do you know a way to check what could have gone wrong in resolving the conflict? We are not using git commands, instead we use SourceTree for working with git and sometimes VS, sometimes TortoiseMerge to resolve conflicts. – chriemmy May 30 '18 at 08:28
  • No, I'm afdaid I have not used those tools much. Well I use VS but not for the git. – max630 May 30 '18 at 22:59