仅显示 Git 日志中一个分支的历史记录

发布于 2024-10-11 02:40:34 字数 529 浏览 7 评论 0原文

我正在为我的项目使用 Git,并尝试遵循最佳实践:

  1. 我在主题分支上工作。
  2. 准备好后,我将主题分支合并到我的开发中em> 使用 git merge --squash 进行分支。这使我的 dev 分支保持干净。
  3. 每当 dev 分支稳定且团队决定发布版本时,我们就会将 dev 分支合并到 master 分支,不使用压缩,并将其标记为版本发布。

这应该保留我们的历史记录,并且使用 gitk,我们可以看到所有提交的来源。但是,我希望能够看到应用于master 分支机构。我已经尝试过:

git log master
git show-branch

这些都没有仅仅显示master分支的历史。有没有办法轻松做到这一点?

I am using Git for my project and trying to follow best practice:

  1. I work on a topic branch
  2. When ready, I merge the topic branch into my dev branch using git merge --squash. This keeps my dev branch clean.
  3. Whenever the dev branch is stable and the team decides it's time for a release, we merge the dev branch into the master branch, without using squash, and tag that commit as a version release.

This should keep our history, and using gitk, we can see where all of the commits come in. However, I want to be able to see only the commits applied to the master branch. I have tried:

git log master
git show-branch

None of these show just the history of the master branch. Is there a way to easily do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

脱离于你 2024-10-18 02:40:34

如果我理解正确的话,您希望看到合并回 master,而不是这些合并的历史记录。我相信:

git log --merges

会给你你想要的。

更新:添加 --first-parent 应该可以从声音中解决这个问题。

git log --merges --first-parent

--第一父级

在看到合并提交时仅遵循第一个父提交。

此选项可以提供更好的概览
当观察一个事物的演化过程时
特定主题分支,因为
合并到主题分支往往是
只是关于调整更新
时不时地上游,这
选项允许您忽略
个人承诺纳入您的
这样的合并历史。

If I'm understanding you correctly, you want to see the merges back into master, but not the history of those merges. I believe that:

git log --merges

will give you what you want.

UPDATE: Adding --first-parent should fix this from the sounds of it.

git log --merges --first-parent

--first-parent

Follow only the first parent commit upon seeing a merge commit.

This option can give a better overview
when viewing the evolution of a
particular topic branch, because
merges into a topic branch tend to be
only about adjusting to updated
upstream from time to time, and this
option allows you to ignore the
individual commits brought in to your
history by such a merge.

三月梨花 2024-10-18 02:40:34

不幸的是,Git 不存储提交的分支信息,并且提交不属于分支。 Git 中的分支只是一系列提交中的“移动标签”,而不是人们所期望的一系列提交。

所以基本上你不能显示属于分支的提交,因为 Git 中没有这样的概念。

Unfortunately, Git does not store branch information for a commit, and commits do not belong to a branch. Branches in Git are just "moving tags" in a course of commits and NOT a sequence of commits as one would expect.

So basically you cannot show commits that belong to a branch since there is no such concept in Git.

半暖夏伤 2024-10-18 02:40:34

由于 Git 不存储有关哪个分支是哪个分支的新生信息,因此没有自动方法来猜测您可能想要显示哪个分支。

在这方面,--first-parent 最终不会有帮助,尤其是因为很容易拥有多个主人。考虑一下:(

wc1$ git clone git://shared.com/repo
wc1$ (hack code, git commit)
wc2$ git clone git://shared.com/repo
wc2$ (hack code, git commit, git push somewhere)
wc1$ git fetch origin; git merge origin/master; git push somewhere master;

随意选择一个随机项目并做这个练习。)将其绘制成图表。因此,即使提交被标记为它们所在的分支的名称(因为两者都是主分支),您也无法有意义地绘制“仅一个分支”的图表。

Since Git does not store information about which branch is nascent from which other, there is no automatic way to guess which branch you could possibly want to be shown.

In that regard, --first-parent will not ultimately help, especially since it is easy to have more than one master, for example. Consider:

wc1$ git clone git://shared.com/repo
wc1$ (hack code, git commit)
wc2$ git clone git://shared.com/repo
wc2$ (hack code, git commit, git push somewhere)
wc1$ git fetch origin; git merge origin/master; git push somewhere master;

(Feel free to take a random project and do this exercise.) Graph it. So you cannot meaningfully graph "just one branch", even if the commits were tagged with the name of the branch they were made on (because both are master).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文