简体   繁体   中英

How can I see if Git history was rewritten

I am tracking down a problem where a couple of commits seem to have gone missing from a branch. I am at a loss to explain what happened but need to see if there are any training/process issues that need to be raised with the devs.

Situation: A feature branch was made and some commits made to it (a couple of changes to a javascript file). The time came to merge the feature branch back into master but it was discovered that a feature is missing. The original dev gave me the commit hash and I can see it on github and it claims to be on the feature branch, but when I look at the history of the javascript file on the branch these two commits are simply not there.

Did someone rewrite history of the branch and remove the commits?

If you have the hashes, you can always

git branch --contains 122345abcd

where 12345abcd is the hash you're missing.

Likewise, you can

git rev-list --all | grep 12345abcd

You could use

git log --cherry-mark --left-right --graph --oneline 12345abcd^...feature_branch

to identify rewritten (cherry-picked/rebased) commits between branches. See also https://www.kernel.org/pub/software/scm/git/docs/git-log.html

--cherry-mark
Like --cherry-pick (see below) but mark equivalent commits with = rather than omitting them, and inequivalent ones with +.

--cherry-pick
Omit any commit that introduces the same change as another commit on the "other side" when the set of commits are limited with symmetric difference.

For example, if you have two branches, A and B, a usual way to list all commits on only one side of them is with --left-right (see the example below in the description of the --left-right option). It however shows the commits that were cherry-picked from the other branch (for example, "3rd on b" may be cherry-picked from branch A). With this option, such pairs of commits are excluded from the output.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM