简体   繁体   English

git --no-merged选项如何工作

[英]How does git --no-merged option work

How does the git branch -r --no-merged work? git branch -r --no-merged工作的?

Does it check to see if all commits in one branch already exist in the original parent branch? 它是否检查原始父分支中是否已存在一个分支中的所有提交?

And what about cherry picks? 樱桃采摘怎么样? Is it smart enough to say that a commit from 1 branch has already been cherry picked back into the original parent branch? 是否足够聪明地说1分支的提交已经被挑回原始的父分支?

And if a branch has already been merged and new commits have been added will it pick that branch up as not being merged? 如果已经合并了一个分支并且添加了新的提交,那么它会选择该分支作为未合并的分支吗?

Well, that comments from @Hasturkun says it all to be honest, but you have 3 questions: 嗯,来自@Hasturkun的评论说实话,但你有3个问题:

1. Does it check to see if all commits in one branch already exist in the original parent branch? 1.它是否检查原始父分支中是否已存在一个分支中的所有提交?

Not trying to be repetitive @Hasturkun quote says: "Only list branches whose tips are not reachable from the specified commit". 不要试图重复@Hasturkun引用说: “只列出其提示无法从指定提交到达的分支”。

In this specific case think of the git tree of commits as a tube/underground map. 在这种特定情况下,将提交的git树视为管/地下地图。 You can only travel backwards from one node/station to the other. 您只能从一个节点/站向后移动到另一个节点/站。

master    : - - - -0 
                    \   
branchA   :          E - - - - F - - - - G

If on master you run git branch --no-merge and taking the manual page definition? 如果在master运行git branch --no-merge并进行手动页面定义? Can you reach G (the tip of of branchA ) from master 's HEAD, commit 0? 你能从master的HEAD到达G( branchA的尖端),提交0吗? No you can't, so branchA will be listed as a non-merged branch. 不,你不能,所以branchA将被列为非合并分支。

How about if you run git branch --no-merge from the HEAD of branchA (commit G)? 如果从branchA (提交G)的HEAD运行git branch --no-merge怎么样? Will master be a non-merged branch? master会不会成为非合并分支? No, it is considered a merged branch, trivial to understand why given the example before. 不,它被认为是一个合并的分支,很容易理解为什么给出前面的例子。

How about this example? 这个例子怎么样?

master    : - - - -0
                    \   
branchA   :          E - - - - F - - - - G - - - Z
                               \                /
branchB   :                     Y - - - W - - -

Output of running git branch --no-merged in all 3 branches: 运行git分支的输出 - 在所有3个分支中未合并:

master
  branchA
  branchB
branchA (nothing)
branchB (nothing)

2. And what about cherry picks? 樱桃采摘怎么样? Is it smart enough to say that a commit from 1 branch has already been cherry picked back into the original parent branch? 是否足够聪明地说1分支的提交已经被挑回原始的父分支?

Cherry-picks create a completely different commitId, so I only use them when I really have to. Cherry-picks创建了一个完全不同的commitId,因此我只在必要时才使用它们。 Since it creates a completely different commit, the trees will differ: 由于它创建了完全不同的提交,因此树将有所不同:

Look at this experiment I just did, consider master and branchA the same: 看看我刚做的这个实验,考虑master和branchA相同:

Experience 1) Using merge 经验1)使用合并

(master)$ touch empty && git add . && git commit -am "File Added"
(master)$ checkout branchA
(branchA)$ git branch --no-merged
  master
(branchA)$ git merge master
(branchA)$ git branch --no-merged
  // outputs nothing

Experience 2) Using cherry-pick 经验2)使用樱桃挑选

(master)$ touch empty && git add . && git commit -am "File Added"
(master)$ checkout branchA
(branchA)$ git branch --no-merged
  master
(branchA)$ git cheery-pick <commitID from above>
(branchA)$ git branch --no-merged
  master

3. And if a branch has already been merged and new commits have been added will it pick that branch up as not being merged? 3.如果已经合并了一个分支并且添加了新的提交,那么它会选择该分支作为未合并的分支吗?

Yes, because of all stated above. 是的,因为上述所有内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM