【问题标题】:How to review a specific commit on Git如何在 Git 上查看特定的提交
【发布时间】:2013-11-15 03:28:19
【问题描述】:

我使用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 命令中发送,但提交 "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

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

【问题讨论】:

    标签: git gerrit git-commit git-review


    【解决方案1】:

    在新分支中创建 B 提交。

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

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

    如果你的历史是这样的:

    ...-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 提交

    【讨论】:

    • 是的,在基于远程分支的分支上创建提交 B(因此没有提交 A)。最好为每个要推送审查的提交创建一个分支(除了一些提交相互依赖)。
    • 好的,我创建了一个新分支并移至该分支。我在这个新分支上做了一个新的提交,但是,当我执行“git review”时,GIT 说“你有多个要提交的提交。”,我的意思是,GIT 显示来自“master”分支的提交和“新”分支,不仅来自“新”分支。我预计只有 1 个提交,来自“新”分支。
    • @Lobo 你的新分支是否依赖于主分支?
    • @Lobo 我更新了我的答案。您的新分支是基于 A 提交还是基于已合并的提交?
    • @RudyBunel 我的新分支基于提交 A。
    【解决方案2】:

    分支就是答案:

    如果你还没有提交 A,那么在提交 A 之前创建分支 A,然后将你的代码提交到该分支并提交以供审核 然后,回到master创建分支B,提交到分支B并提交审核。 这样可以确保没有依赖关系。

    好的,现在假设您已经像这样在 master 中提交了所有内容:

    M----A----B
    

    这是你的日志:

    commit b58fff12319d7ad1b1bc6ebcf4395d986a8ffac3
    Author: 
    Date:   Fri Nov 8 09:48:23 2013 +0800
    
        Change B
    
    commit 99f249cdf2352ace3ca9ee8bf7a8a732f27b31eb
    Author: 
    Date:   Fri Nov 8 09:47:56 2013 +0800
    
        Change A
    
    commit f091b7a4cc5c0532973c5bd401d2171f6fb735ec
    Author: 
    Date:   Fri Nov 8 09:47:30 2013 +0800
    
        Initial commit
    

    我们想要的是这样的:

        A
      / 
     /
    M 
     \
      \
       B
    

    要获得此创建,请执行以下命令:

    # Create two new branches from the point where the current Gerrit repo master is now
    git branch A f091b7a4cc5c0532973c5bd401d2171f6fb735ec
    git branch B f091b7a4cc5c0532973c5bd401d2171f6fb735ec
    git checkout A # Create a branch to hold change A
    git merge 99f249cdf2352ace3ca9ee8bf7a8a732f27b31eb
    git log
    commit 99f249cdf2352ace3ca9ee8bf7a8a732f27b31eb
    Author: 
    Date:   Fri Nov 8 09:47:56 2013 +0800
    
        Change A
    
    commit f091b7a4cc5c0532973c5bd401d2171f6fb735ec
    Author: 
    Date:   Fri Nov 8 09:47:30 2013 +0800
    
        Initial commit
    git checkout B 
    git cherry-pick b58fff12319d7ad1b1bc6ebcf4395d986a8ffac3
    git log
    # Note the new sha1 hash as this is change could not be fast forwarded
    commit d3aa1acc2b208115c7de78d5c9c4f6a906ece84a
    Author: 
    Date:   Fri Nov 8 09:48:23 2013 +0800
    
        Change B
    
    commit f091b7a4cc5c0532973c5bd401d2171f6fb735ec
    Author: 
    Date:   Fri Nov 8 09:47:30 2013 +0800
    
        Initial commit
    

    现在您有两个分支,每个分支都保存一个更改,将这些更改中的任何一个推送到 Gerrit 都会导致仅推送一个更改。

    然后你可能想通过从那里删除提交来清理你的主人:

    git checkout master
    git reset --hard HEAD~2
    

    专门针对更新问题:

    git branch B 6751c7d 
    git checkout B
    git cherry-pick 531bd84 
    

    你应该从gerrit master 675c7d创建分支,然后cherry-pick你的提交3到新分支,然后你可以删除你的旧分支delete_role

    【讨论】:

    • 我在“master”分支中有 2 个提交。我创建了一个新分支,然后更改为这个新分支。我做了一些更改并做出了新的提交。现在,当我启动“git review”时,GIT 会说“你要提交的提交不止一个。”
    • 我预计只有 1 个提交提交审核。
    • 您是否像现在在 Gerrit 上一样从 master 制作了分支?您应该从 Gerrit master 现在所在的位置开始分支。
    • 我更新了我的问题。我从以前的提交开始创建新分支,而不是从 Gerrit master 开始。我现在该怎么办?我不想丢失我之前发送给 Gerrit 的提交。
    • git branch B 6751c7d git checkout B git cherry-pick 531bd84 你应该从gerrit master 675c7d创建分支,然后cherry-pick你的提交3到新分支,然后你可以删除你的旧分支删除角色
    【解决方案3】:

    推送提交“A”后,您可以重置本地分支并开始处理提交“B”。因为每次提交/更改都可以在被推送到审查分支后从 Gerrit 中签出。您可以在每个补丁集下载面板从 Gerrit 审查委员会获取命令。一个例子:

    git fetch https://android.googlesource.com/kernel/tegra refs/changes/43/69243/2 && git checkout FETCH_HEAD
    

    检查更改后,可以对其进行修改并作为新补丁集再次推送。所以你不必每次提交都使用本地分支。

    【讨论】:

      【解决方案4】:

      在我看来,你在工作的地方有分支,然后你有提交 A,下一个提交 B 也在同一个分支中。所以从逻辑上讲,它们并不相互依赖,但对于历史来说,这些变化是相互依赖的。因此,第一个提交 A 需要审核并合并到工作分支,然后才能合并第二个 B。

      现在,当您将引用推送到审核时,Gerrit 已经通过更改 id 知道您推送了哪些内容以进行审核。如果您推送分支来审核,则只会发送新的提交,或者更新或重新定位的提交。

      长话短说。 Gerrit 知道什么是新的,什么已经在审查中。

      【讨论】:

        猜你喜欢
        • 2016-07-25
        • 2021-02-27
        • 2014-01-28
        • 2013-07-07
        • 2013-11-28
        • 2021-04-16
        • 2012-12-06
        • 1970-01-01
        • 2011-02-26
        相关资源
        最近更新 更多