git 显示自分支创建以来的提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9725531/
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
show commits since branch creation
提问by lurscher
Is there a way to see with git log
or some other command only the commits that were added after branch creation?
有没有办法只查看git log
分支创建后添加的提交或其他命令?
usage: git log [<options>] [<since>..<until>] [[--] <path>...]
or: git show [options] <object>...
--quiet suppress diff output
--source show source
--decorate[=...] decorate options
采纳答案by Alan Thompson
Full documentation is here: https://www.kernel.org/pub/software/scm/git/docs/gitrevisions.html
完整文档在这里:https: //www.kernel.org/pub/software/scm/git/docs/gitrevisions.html
Suppose you have a repo that looks like this:
假设你有一个看起来像这样的仓库:
base - A - B - C - D (master)
\
\- X - Y - Z (myBranch)
Verify the repo status:
验证回购状态:
> git checkout master
Already on 'master'
> git status ; git log --oneline
On branch master
nothing to commit, working directory clean
d9addce D
110a9ab C
5f3f8db B
0f26e69 A
e764ffa base
and for myBranch:
对于 myBranch:
> git checkout myBranch
> git status ; git log --oneline
On branch myBranch
nothing to commit, working directory clean
3bc0d40 Z
917ac8d Y
3e65f72 X
5f3f8db B
0f26e69 A
e764ffa base
Suppose you are on myBranch, and you want only changes SINCE master. Use the two-dot version:
假设您在 myBranch 上,并且只想更改 SINCE master。使用两点版本:
> git log --oneline master..myBranch
3bc0d40 Z
917ac8d Y
3e65f72 X
The three-dot version gives all changes from the tip of master to the tip of myBranch. However, note that the common commit B is not included:
三点版本给出了从 master 尖端到 myBranch 尖端的所有变化。但是,请注意,不包括公共提交 B:
> git log --oneline master...myBranch
d9addce D
110a9ab C
3bc0d40 Z
917ac8d Y
3e65f72 X
PLEASE NOTE: git log
and git diff
BEHAVE DIFFERENTLY!The behavior is not exactly opposite, but almost:
请注意: git log
并git diff
表现出不同!行为并不完全相反,但几乎:
> git diff master..myBranch
diff --git a/rev.txt b/rev.txt
index 1784810..e900b1c 100644
--- a/rev.txt
+++ b/rev.txt
@@ -1 +1 @@
-D
+Z
> git diff master...myBranch
diff --git a/rev.txt b/rev.txt
index 223b783..e900b1c 100644
--- a/rev.txt
+++ b/rev.txt
@@ -1 +1 @@
-B
+Z
So, the two-dot version shows the diff from tip of master (i.e. D) to tip of myBranch (Z). The three-dot version shows the difference from the base of myBranch (i.e. B) to the tip of myBranch (Z).
因此,两点版本显示了从 master 的尖端(即 D)到 myBranch 的尖端(Z)的差异。三点版本显示了从 myBranch 底部(即 B)到 myBranch 尖端(Z)的差异。
回答by Matt Meng
I was incorrect with my original answer. You want the double dot notation:
我的原始答案不正确。你想要双点符号:
git log master..<your_branch_name>
I got different results than I was expecting, so I did a test with the following repo structure:
我得到了与预期不同的结果,因此我使用以下 repo 结构进行了测试:
a - - c - e - - g - i master
\ b - d / \ f - h test
I then tried git log master..test
:
然后我尝试git log master..test
:
f - h
And then git log master...test
:
然后git log master...test
:
- g - i
f - h
So double dot shows the commits in test
but not in master
(^master temp
) and triple dot shows commits in master
AND test
but not in both.
所以双点显示提交test
但不在master
( ^master temp
) 中,三点显示提交在master
ANDtest
但不在两者中。
The other excellent answer in this question got it right first and has a better explanation (https://stackoverflow.com/a/24769534/1185838); it should probably be marked as the answer instead of mine. You can also reference this answer (https://stackoverflow.com/a/463027/1185838) which helped me better understand the difference between double dot and triple dot notation.
这个问题中的另一个很好的答案首先是正确的,并且有更好的解释(https://stackoverflow.com/a/24769534/1185838);它可能应该被标记为答案而不是我的。您还可以参考这个答案(https://stackoverflow.com/a/463027/1185838),它帮助我更好地理解双点和三点表示法之间的区别。
Apologies for the incorrect answer!
为错误的答案道歉!
Old Answer - Incorrect
旧答案 - 不正确
Use three periods to reference the commit at which the second branch diverged from the first, or in this case your branch diverged from master:
使用三个句点来引用第二个分支与第一个分支不同的提交,或者在这种情况下您的分支与 master 分支:
git log master...<your_branch_name>
Make sure to use threeperiods for this case.
确保在这种情况下使用三个句点。
Side-Note:You can also leave off your branch name as git automatically references the HEAD pointer in that case, for example:
旁注:您也可以省略分支名称,因为在这种情况下 git 会自动引用 HEAD 指针,例如:
git log master...
is equivalent to my previous example. This works anywhere a commit comparison is available.
相当于我之前的例子。这适用于任何可用的提交比较。
回答by Shaun Luttin
If you're on the branch that you created:
如果您在创建的分支上:
git log master..
回答by Sandro Munda
Yes it's possible to compare your "new" branch with the master branch (commonly named : "master"):
是的,可以将您的“新”分支与主分支(通常命名为:“master”)进行比较:
git log master..<your_branch_name>
Of course, replace <your_branch_name>
.
当然,更换<your_branch_name>
。
回答by Ethan Hodys
I could be wrong but I don't think any of the answers are exactly was being asked for in the OP so I wanted to add a new answer. I believe that this is the exact same question I had since in other source control systems this is very easy to do.
我可能是错的,但我认为 OP 中并没有完全要求任何答案,所以我想添加一个新答案。我相信这与我遇到的问题完全相同,因为在其他源代码控制系统中这很容易做到。
I have the following in MASTER:
我在 MASTER 中有以下内容:
'develop' | --> 'GP603'
'发展' | --> 'GP603'
In ORIGIN (my local system) I have:
在 ORIGIN(我的本地系统)中,我有:
'GP603' [CLONED from the remote/GP603 branch]
'GP603' [从远程/GP603 分支克隆]
I then performed 2 different commits. First commit change File X. Second commit change File X and File Y. Some day later I wanted to just validate my assumption of the state of the local branch ORIGIN/GP603. This is what I did to validate that there were only he 2 commits I remembers doing (which in reality were the only 2 commits on the branch)
然后我执行了 2 个不同的提交。第一次提交更改文件 X。第二次提交更改文件 X 和文件 Y。一天后,我只想验证我对本地分支 ORIGIN/GP603 状态的假设。这就是我所做的,以验证我记得他只有 2 次提交(实际上是分支上仅有的 2 次提交)
$ git log origin/GP.603...
$ git log origin/GP.603 ...
(Commit 2) commit b0ed4b95a14bb1c4438c8b48a31db7a0e9f5c940 (HEAD -> GP.603) Author: xxxxxxx Date: Wed xxxxx -0400
(提交 2) 提交 b0ed4b95a14bb1c4438c8b48a31db7a0e9f5c940 (HEAD -> GP.603) 作者:xxxxxxx 日期:星期三 xxxxx -0400
1. Fixed defect where the format of the file names and paths were being added to HashTable in such a way that they would never be matched in any comparison. This was an
defect causing older failed files to never be moved to the correct directory (WindowsServiceApplication.cs)
2. Removing worthless and contextless message as it does nothing but clog the log with garbage making it harder to read (DinoutFileHandler.cs)
(Commit 1) commit 2c4541ca73eacd4b2e20d89f018d2e3f70332e7e Author: xxxxxxx Date: Tue Oct xxxxx -0400
(提交 1)提交 2c4541ca73eacd4b2e20d89f018d2e3f70332e7e 作者:xxxxxxx 日期:10 月 xxxxx -0400
In ProcessFile() function need to perform a .ToLower() on the file path string when adding it o the failedFiles collection.
回答by Konrad Viltersten
I get often into the mode of oh, dear God, what have I done. Specifically, the haunting fear regards the latest changes in the current branch. It's nice to see the blame game of commits, which I do as follows. (Assuming you're in the currentbranch of interest and have branched it out from dev.)
我经常进入哦,亲爱的上帝,我做了什么。具体来说,令人难以忘怀的恐惧是关于当前分支的最新变化。很高兴看到提交的责备游戏,我是这样做的。(假设您在当前感兴趣的分支中并且已经从dev分支出来。)
git log --oneline dev..
git log --oneline dev..
It gives me the list of commits I've done to track back to the place where mayhem, sodom and gomorra aren't the reality. Also, it helps if you commit obsessively like a ADHD monkey on LSD. Once I've got my bearings list, I can narrow it down and analyse as documented in this article- there's a section on limiting the output at the bottom.
它为我提供了我所做的提交列表,以追溯至混乱、鸡奸和戈莫拉不存在的地方。此外,如果您像 LSD 上的多动症猴子一样痴迷于承诺,它也会有所帮助。一旦我有我的轴承名单,我可以缩小范围,并作为记录分析文章-有限制上,在底部的输出部分。