Changes were pushed on our Git branch and it modified files. However, these commits don't show these files being changed. Does anyone know the cause?

Viewed 55

There were commits on our branch which added .ts files. However, it seems that Java files were also changed as well. But the commits for the ts files did not show java files being committed. What could have caused this? I had to revert to a previous commit then manually copy the files from the old commit to the latest?

In the pic below: [Removed]

I checked out Github repository as well, and the java file changes were pushed. But the latest commit pushed to the repository no longer reflects these changes and Github says only ts files were added/modified

1 Answers
* cccccc  -- HEAD, main -- changes made in bbbbbb missing here
* aaaaaa  -- merge commit by user1
|\
| *  bbbbbb - commit by user2 whose changes disappeared
* |  abcdef - commit by user1
|/
* fedcba - parent commit

This happened to me a few times, usually when someone who is new to git does a merge and does not understand how it works exactly.

Specifically, they did it an advanced merge using the "ours strategy" (not the "ours recursive option"), like it is described here: https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging

If you want to do something like this but not have Git even try to merge changes from the other side in, there is a more draconian option, which is the “ours” merge strategy. This is different from the “ours” recursive merge option.

This will basically do a fake merge. It will record a new merge commit with both branches as parents, but it will not even look at the branch you’re merging in. It will simply record as the result of the merge the exact code in your current branch.

Looks like this was the case with the merge commit aaaaa (later edited for privacy reasons) done by user1 (later edited username for privacy reasons).

Related