开发者

Getting the information of squashed commits in Git

I squash some commits in Git using git rebase -i origin/master as mentioned in ReinH.com.

After squashing some commits, is there a way to see the original commits? Is it possible to get "开发者_运维百科diff" of the commits? Can I get the SHA?

If it's possible, is that still possible after running git gc?


The point of squashing commits is to rewrite history, replacing the original commits with a single commit.

That said, it's hard to make things actually disappear in git. The easiest way to get at those commits will be via git reflog. Try git reflog <branch> for the previous positions of the branch which you rebased.

You should be able to find the SHA1 of the tip of the branch just before your interactive rebase. (If the branch no longer exists, try git reflog show to see the reflog of HEAD. It should be there too, just more other activity to sort through.)

Once you have the SHA1, you're golden - use git log -p or gitk to view the commits and see their diffs. (If you want to do a lot with it, create a branch there, so you don't have to paste the SHA1 over and over again.)

This will still be possible after running git gc, as long as it hasn't been a long time since you squashed those commits. gc only prunes unreachable dangling objects over a certain age.

Commits are considered reachable if they're reachable from anything in the reflogs, and reflogs take 90 days to expire, so you can generally count on those original commits hanging around for three months.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜