简体   繁体   English

我如何从git压缩的提交中获取最后的提交

[英]How can i get the last commit from squashed commit in git

I want to have the 我想要

1. Commit hash
2. commit date
3. commit author
4. commit message from last commit

My problem is that if i use git log -1 then it shows all the squashed commits but i only want to have the latest commit from those squeashed commits 我的问题是,如果我使用git log -1那么它会显示所有压缩的提交,但是我只想从这些压缩的提交中获取最新的提交

A squashed commit is a new commit made of the merging of other commits. 压缩的提交是由其他提交合并而成的新提交。 Unlike a merge, it doesn't retain any reference to its component commits. 与合并不同,它不保留对其组件提交的任何引用。 You can't get back to any of the original commits through the squashed commit. 通过压缩的提交,您无法返回到任何原始提交。 You may be able to find the original commits in the reflog if they're still hanging around in the object's folder. 如果原始提交仍在对象的文件夹中徘徊,则可以在引用日志中找到它们。

Here's an example branch with 4 commits, A being the first, D being the most recent: 这是一个具有4个提交的分支示例, A是第一个提交, D是最近的提交:

A - B - C - D

If you rebase to squash C into B , a new commit E is made of those two commits, and it's parent is A . 如果您将C压缩为B ,则由这两个提交组成一个新的提交E ,其父级为A D is copied to a new commit - - with a different committer time, and with a parent of B (instead of C ): D复制到新提交具有不同的提交者时间,并使用B的父B (而不是C ):

A - E - D¹

The original B and C will exist for awhile, but they won't be referenced (unless something else in the commit DAG also referenced them), and eventually they'll expire. 原始的BC将存在一段时间,但是它们不会被引用(除非在提交DAG中的其他内容也引用了它们),最终它们将过期。 This is where they'd be if you could see them: 如果可以看到它们,这就是它们的位置:

A - E - D¹
 \
  \
    B - C - D  (these are no longer visible)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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