如何查看 Git 上的特定提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19768959/
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
How to review a specific commit on Git
提问by Lobo
I sent a commit (named "A commit") to review (Gerrit) using git review
command.
我使用git review
命令发送了一个提交(名为“A commit”)来(Gerrit)。
Now, I make a new commit (named "B commit") and I want to send it to review as well, but I don't want to re-send the "A commit". There is no dependencies each other.
现在,我做了一个新的提交(名为“B 提交”),我也想将它发送给,但我不想重新发送“A 提交”。彼此之间没有依赖关系。
How to send a review to gerrit for a specific commit?.
如何针对特定提交向 gerrit 发送评论?
UPDATE:
更新:
$ 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)
Commit "df68f1a" and "4ce2d8d" are dependant and they have been sent in a previous git review
command, but commit "531bd84" belongs to a new branch (delete_role) because is a new issue.
提交“ 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
I want to send to Gerritonly the "531bd84" commit, not the other ones.
我只想向Gerrit 发送“ 531bd84”提交,而不是其他提交。
回答by Rudy Bunel
Create the B commit in a new branch.
在新分支中创建 B 提交。
While being on this branch, use git review
and it will only push the content of this branch to Gerrit.
在这个分支上,使用git review
它只会将这个分支的内容推送到 Gerrit。
This way, Gerrit won't consider that your commit B needs your commit A and if you want, you can merge your commit B to the working branch before commit A
这样,Gerrit 不会认为你的提交 B 需要你的提交 A,如果你愿意,你可以在提交 A 之前将你的提交 B 合并到工作分支
If your history is like this:
如果你的历史是这样的:
...-old(merged)-A(waiting for review)
what you want to do is:
你想要做的是:
...-old(merged)-A(waiting for review) <-master branch
\B(new commit) <-new branch
Then, if you're on branch B, and use git review
, it won't push anything else than commit B
然后,如果您在分支 B 上并使用git review
,它不会推送除提交 B 之外的任何内容
If you're in this situation:
如果您处于这种情况:
...-old(merged)-A(waiting for review)-B
, what you want to do to achieve the configuration we want is:
,要实现我们想要的配置要做的是:
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)
Now, you achieved the wanted configuration and to push your B commit, you just need to do:
现在,您实现了想要的配置并推送您的 B 提交,您只需要执行以下操作:
git checkout Breview
git review
and it will only submit your B commit
它只会提交你的 B 提交
回答by uncletall
Branches are the answer:
分支是答案:
If you have not made commit A then before making commit A make branch A, then commit your code to that branch and submit it for review Then, go back to the master and create branch B, commit to branch B and submit for review. This way you ensure that there are no dependencies.
如果您还没有提交 A 那么在提交 A 之前先创建分支 A,然后将您的代码提交到该分支并提交以供 然后,返回 master 并创建分支 B,提交到分支 B 并提交以供。这样您就可以确保没有依赖项。
Ok, now lets say that you have committed everything in the master like this:
好的,现在假设您已经像这样提交了 master 中的所有内容:
M----A----B
This is your log:
这是你的日志:
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
What we want is this:
我们想要的是这样的:
A
/
/
M
\
\
B
To get this create perform the following commands:
要获得此创建,请执行以下命令:
# 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
Now you have two branches that hold one change each, pushing either of these changes to Gerrit will result in just one change being pushed.
现在你有两个分支,每个分支都保存一个更改,将这些更改中的任何一个推送到 Gerrit 将导致只推送一个更改。
Then you might want to clean up you master by remove the commits from there:
然后你可能想通过从那里删除提交来清理你的主人:
git checkout master
git reset --hard HEAD~2
Specially for the update question:
专门针对更新问题:
git branch B 6751c7d
git checkout B
git cherry-pick 531bd84
You should create the branch from the gerrit master 675c7d, then cherry-pick your commit 3 into the new branch, then you can delete your old branch delete_role
您应该从 gerrit master 675c7d 创建分支,然后将您的提交 3 挑选到新分支中,然后您可以删除旧分支 delete_role
回答by Mateusz
The way I see it you have branch where you work, then you have commit A and next commit B is also in the same branch. So logically they don't depend on each other but for history those changes are dependent. So first commit A will need review and be merged to working branch before second B could be merged in.
我认为你有你工作的分支,然后你有提交 A 和下一个提交 B 也在同一个分支中。所以从逻辑上讲,它们并不相互依赖,但对于历史而言,这些变化是相互依赖的。因此,第一次提交 A 将需要并合并到工作分支,然后才能合并第二次 B。
Now when you push references to review, Gerrit already knows by change id's what you have pushed for review. If you push branch to review only new commits will be sent, or commits that were updated or rebased.
现在,当您推送引用进行时,Gerrit 已经通过更改 id 知道您推送的内容。如果你推送分支来只会发送新的提交,或者更新或重新设置的提交。
Long story short. Gerrit knows what is new and what is already in review.
长话短说。Gerrit 知道什么是新的,什么已经在中。
回答by HiB
After pushing commit 'A' you can reset the local branch and start working on commit 'B'. Since every commit/change can be checked out from Gerrit later once it was pushed to review branch. you can get the command from Gerrit review board at each patchset download panel. an example:
推送提交“A”后,您可以重置本地分支并开始处理提交“B”。因为每次提交/更改都可以在被推送到分支后从 Gerrit 检出。您可以在每个补丁集下载面板从 Gerrit 委员会获取命令。一个例子:
git fetch https://android.googlesource.com/kernel/tegra refs/changes/43/69243/2 && git checkout FETCH_HEAD
After checking out a change it can be amend and pushed again as a new patchset. So you dont have to use local branches for each commit.
检查更改后,可以对其进行修改并作为新补丁集再次推送。所以你不必为每个提交使用本地分支。