Does Git leave any evidence that a rebase ever even occurred after the fact?

55 views Asked by At

I understand that a rebase rewrites history. But is there any record or sign that a rebase occurred left in the repository after the fact?

1

There are 1 answers

0
larsks On

There is nothing recorded in the repository history that indicates a rebase has occurred.

In the local repository in which they rebase was performed, git reflog will show the rebase operation:

$ git reflog
e15c93a HEAD@{2}: commit: Fix transposed apiversion/kind fields
594577c HEAD@{3}: rebase (finish): returning to refs/heads/main
594577c HEAD@{4}: rebase (pick): Ignore generated files
99e5acd HEAD@{5}: rebase (fixup): Run linters before building
3f1a5e6 HEAD@{6}: rebase (fixup): # This is a combination of 2 commits.
e572c0d HEAD@{7}: rebase (start): checkout HEAD~4
ed31f54 HEAD@{8}: commit: fixup

If there exist multiple copies of the repository, you can identify a rebase by noting if the history differs between the different copies (in particular, if you see the same commit message associated with different commit ids in different copies of the repository). For example, here's the last 10 commits in the repository for GNU hello:

$ git log --oneline -10 origin/master
fab5dca gnulib: remove use of deprecated module non-recursive-gnulib-prefix-hack
54660e5 maint: post-release administrivia
8ed6c0e version 2.12.1
c8a7bad doc: add NEWS for 2.12.1
9af4fc2 doc: fix grammar in hello.x (thanks, Logan!)
101ccb1 maint: post-release administrivia
6fe9c7f maint: add NEWS for 2.12
8f59815 version 2.12
113f5b4 maint: allow atexit-1 test to work when wprintf failed
66f4cdd tests: remove multibyte-1 test

And here's the same thing for my local checkout of that repository in which I have amended one of the commits:

$ git log --oneline -10
bee78c6 gnulib: remove use of deprecated module non-recursive-gnulib-prefix-hack
5aa89a0 maint: post-release administrivia
f8542d6 version 2.12.1
47f90b4 doc: add NEWS for 2.12.1
adc57c6 doc: fix grammar in hello.x (thanks, Logan!)
101ccb1 maint: post-release administrivia
6fe9c7f maint: add NEWS for 2.12
8f59815 version 2.12
113f5b4 maint: allow atexit-1 test to work when wprintf failed
66f4cdd tests: remove multibyte-1 test

Note how the commits ids are different start with the commit titlted doc: fix grammar in hello.x (thanks, Logan!). That's the commit I modified, so everything after that has a new commit id.

Lastly, if you try to git pull from a repository that has been rebased since you last pulled it, you will see in the output of git pull a forced update message:

 + fab5dca...bee78c6 master     -> origin/master  (forced update)

This indicates that the remote history has been modifed from what it looked like last time you pulled the repository.