I am running into a strange issue that is causing work to be lost. A coworker made a commit a few days ago into a remote branch. Sometime yesterday that remote branch was merged into master. All the changes from my coworkers one commit were lost. Normally I'd say it was a bad merge and it just overwrote his changes. The logs however don't reflect this. If I check the logs with gitk, I can see commit 3a2b22f (coworkers orginal commit) a good ways down the list, but if I run gitk on the file in question (to check its history) commit 3a2b22f is no where to be seen. Its as if after the merge the commit ceased to exist in the files history.

The questions are:

  1. How on earth did this happen
  2. How does one prevent it from happening again?
有帮助吗?

解决方案

You can use gitk --all -- filename.txt to see the entire history of a file so you can figure out where merges happened, etc. A command line equivalent would be git log --pretty=oneline --graph --all -- filename.txt.

By default, gitk and git log, when given a file name to work with, will only follow the first parent at merges. Specifying the --all flag causes them to include commits on any branch. gitk also has a --merge option that may be pertinent here, and of course git log has way too many different options to keep track of that can affect which commits are displayed and how the display is done.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top