Git 日志变基

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8979189/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 06:23:08  来源:igfitidea点击:

Git log rebases

gitgit-rebasegit-log

提问by mustard

I know that GIT rebases will rewrite the history -- i.e. the commit ids will change. However, Is there any way to trace when a branch was rebased and from which branch?

我知道 GIT 变基会重写历史——即提交 ID 会改变。但是,有什么方法可以跟踪分支何时重新定位以及来自哪个分支?

EDIT: I have a development branch 'A' and a topic branch 'B'. 'A' is shared by the team. At some point, 'A' has been re-based with a mainstream branch. As a result of the re-base (and subsequent commits), when I updated the topic branch, I saw discrepancies. I am trying to find out the correct person to talk to to resolve the issues.

编辑:我有一个开发分支“A”和一个主题分支“B”。'A' 由团队共享。在某些时候,'A' 已经重新基于主流分支。由于 re-base(以及随后的提交),当我更新主题分支时,我看到了差异。我正在努力寻找合适的人与之交谈以解决问题。

回答by Cascabel

You can probably tell who did it! When you rebase, since the commits are rewritten, the committer information will be from the person doing the rebase, not the original author. (This is separate from the author information.)

你大概知道是谁干的!当你变基时,由于提交被重写,提交者信息将来自执行变基的人,而不是原作者。(这与作者信息是分开的。)

You can see this information in gitk(in the diff pane in the lower left) or in the output of git log --pretty=fuller(as in more full than full). Example log output:

您可以在gitk(在左下角的差异窗格中)或在git log --pretty=fuller(如更完整而不是完整)的输出中看到此信息。示例日志输出:

commit b8624718b97a39a04637c91ec3517c109f3f681d
Author:     Original Author <[email protected]>
AuthorDate: Sun Aug 8 02:15:10 2010 -0300
Commit:     New Committer <[email protected]>
CommitDate: Mon Jan 23 17:29:39 2012 -0800

    a lovely commit message

...

The committer name, email, and date are from the operation that actually wrote the commit. Note that if it's been rewritten multiple times, you'll only have the most recent information.

提交者姓名、电子邮件和日期来自实际编写提交的操作。请注意,如果它被多次重写,您将只拥有最新的信息。

As for where it was rebased from... if the original version of the rebased commits are also in your history, that's easy. Just search the full history for a matching commit, for example by a fragment of the commit message, or by something that was changed in the commit:

至于它是哪里重新定位……如果重新定位的提交的原始版本也在您的历史记录中,那很容易。只需搜索匹配提交的完整历史记录,例如通过提交消息的片段或提交中更改的内容:

git log --all --grep='commit subject from a rebased commit'
git log --all -S'void this_function_was_added() {'

If you don't have the original commit anywhere in history anymore, that's going to be tougher. Hopefully you'll be able to find out by tracking down the person who did it, and if they don't know, asking them to run git reflog show <branch>in their repository, to see the history of that branch.

如果您在历史上的任何地方都没有原始提交,那将更加困难。希望您能够通过追踪执行此操作的人来找出答案,如果他们不知道,请让他们git reflog show <branch>在他们的存储库中运行,以查看该分支的历史记录。

回答by idlethread

git reflog

will allow you to look at the history of all your git workflow. On a project I'm working on, here are the top three reflog entries:

将允许您查看所有 git 工作流程的历史记录。在我正在进行的一个项目中,以下是前三个 reflog 条目:

151a1da HEAD@{0}: filter-branch: rewrite
db8c822 HEAD@{1}: checkout: moving from fixes to master
db8c822 HEAD@{2}: checkout: moving from master to fixes

The first column shows the SHAID. So you can use the standard git commands on this SHAID e.g. git show 151a1da

第一列显示 SHAID。所以你可以在这个 SHAID 上使用标准的 git 命令,例如 git show 151a1da

回答by nulltoken

Reflogis a mechanism to record when the tip of branches are updated. This command is to manage the information recorded in it.

Reflog是一种记录分支提示何时更新的机制。该命令是对记录在其中的信息进行管理。

"Basically every action you perform inside of Git where data is stored, you can find it inside of the reflog. Git tries really hard not to lose your data, so if for some reason you think it has, chances are you can dig it out using git reflog. What this means is that you can use it as a safety net: you shouldn't be worried that a merge, rebase, or some other action will destroy your work since you can find it again using this command."

“基本上你在存储数据的 Git 中执行的每一个操作,你都可以在 reflog 中找到它。Git 非常努力地不丢失你的数据,所以如果由于某种原因你认为它丢失了,你很可能可以把它挖出来使用 git reflog。这意味着您可以将其用作安全网:您不必担心合并、变基或其他某些操作会破坏您的工作,因为您可以使用此命令再次找到它。”

More on this subject in

有关此主题的更多信息