git - 如何查看 Git 上的特定提交

标签 git gerrit git-commit git-review

我使用 git review 命令发送了一个提交(名为“A commit”)以审查 (Gerrit)。

现在,我做了一个新提交(名为“B 提交”),我也想将它发送给审查,但我不想重新发送“A 提交”。互不依赖。

如何向 gerrit 发送特定提交的评论?

更新:

$ git add --all


$ git status

# On branch delete_role
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   path/to/file.ext


$ git status

# On branch delete_role
nothing to commit (working directory clean)


$ git branch

*delete_role
 master


$ git log --graph --decorate --oneline -n13

* 531bd84 (HEAD, delete_role) commit 3
* df68f1a (master) commit 2
* 4ce2d8d commit 1
*   6751c7d (origin/master, origin/HEAD, gerrit/master)

提交“df68f1a”和“4ce2d8d”是相关的,它们已在之前的 git review 命令中发送,但提交“< strong>531bd84"属于新分支 (delete_role),因为是新问题。

$ git review

You have more than one commit that you are about to submit.
The outstanding commits are:

531bd84 (HEAD, delete_role) commit 3
df68f1a (master) commit 2
4ce2d8d commit 1

我想发送给 Gerrit 只有“531bd84”提交,而不是其他提交。

最佳答案

在新分支中创建 B 提交。

在这个分支上,使用git review,它只会将这个分支的内容推送到Gerrit。

这样,Gerrit 就不会认为你的提交 B 需要你的提交 A,如果你愿意,你可以在提交 A 之前将你的提交 B merge 到工作分支

如果你的历史是这样的:

...-old(merged)-A(waiting for review)

你要做的是:

...-old(merged)-A(waiting for review) <-master branch
       \B(new commit)                 <-new branch

然后,如果你在分支 B 上,并使用 git review,它不会推送除提交 B 之外的任何其他内容

如果您处于这种情况:

...-old(merged)-A(waiting for review)-B

,你想要实现我们想要的配置是:

git log (Note the SHA1 of your B commit)
git reset HEAD^^^ (you go back in detched state three commits before, before the two you don't want to send)
git checkout -b Breview (you create a new branch there)
git cherry-pick +the SHA1 you noted (you copy your B commit on your new branch)
git checkout master (you return on your branch with the two commit)
git reset HEAD^--hard (you delete the B commit from this branch where you don't need it)

现在,您实现了所需的配置并推送您的 B 提交,您只需要做:

git checkout Breview
git review

它只会提交你的 B 提交

关于git - 如何查看 Git 上的特定提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19768959/

相关文章:

git - 防止或捕获 git 历史重写的策略

java - Atlassian stash 相当于 git 管理器(开源)

firefox - Gerrit 的 "All side by side"不会在新选项卡中打开差异

linux - GitLab 在 SSH-KEY 注册后请求密码

git - 由于 "port 443: Connection timed out",Docker 构建失败

git - 如何最好地使用 git 管理 TYPO3 安装?

git - Gerrit 补丁集依赖于过时的补丁集

git - Gerrit 接受推送而不更改 ID

TFS 中的 Git 提交策略

GIT Pull 删除了我的提交