0

I've been working on a project for some time using a git local repository for version control.

I have two branches in the repository: master and "other" (not its real name).

When I run git branch I get this list:

  other
* master

Looking at my repository graph with gitg (a Gnome GUI for git), selecting "all branches" from the branches drop-down list, I get this graph:

enter image description here

I see the two branches, but there are also two commits, tagged "v1.2y" and "v1.2s", that stick out of the master branch and don't seem to merge back into it. They seem to be hanging there like non-merged-back branches, but they are not actual branches. At least neither git nor gitg list them as being branches.

Can someone explain to me the reason they stick out of the master branch if they are not branches themselves?

Please don't just simply tell me what to do to make it normal but, most importantly, the reason why this happened to begin with.

EDIT: I have never made a rebase or force push.

4

1 回答 1

3

首先,您可以在这里阅读标签和分支之间的区别: 标签与分支有何不同?我应该在这里使用哪个?

假设您执行以下操作:

git checkout master                      //go to branch master, say at commit x
git checkout -b newbranch                //create a new branch called newbranch that also points to x
git commit -a -m some_branch_commit_1    //add a commit to newbranch
git tag tagged_my_commit                 //tag your commit
git checkout master                      //go back to master
git commit -a -m "Something"             //add a commit, say y to master 
git checkout newbranch                   //go back to newbranch
git rebase master                        //create a copy of the commits on newbranch so that they now split of from y instead of x

some_branch_commit_1在这种情况下,将创建一个新的提交副本。然而,旧的仍然存在(它被标记tagged_my_commit)所以它永远不会消失。基本上,您现在有两个相同提交的副本,其中一个不在具有特定名称的分支上。

但是,假设您没有标记该提交,那么原则上它可以被 git 删除。但是,删除此类提交(垃圾收集)只会不时发生。这可以解释为什么不应该继续存在的提交仍然在你的 repostiroy 中。如果您想了解更多信息,请参阅https://git-scm.com/docs/git-gc

正如评论中所指出的,这不仅发生在变基上。任何形式的重写(例如,修改提交、更改分支指针……)都可能导致您遇到这种情况。

按要求编辑:另一个例子

git checkout master                  //go to master, say at commit x
git commit -a -m "I did something"   //create a commit, say y1
git tag tagit                        //tag your commit

你的历史现在看起来像这样

y1  = master  =  tagit
|
x

现在执行以下操作//编辑一些文件
git commit -a -m "I did something (more)" --amend //更改提交 y1 以便它现在也考虑对另一个文件的更改,比如说这是 y2

在这种情况下,您的历史记录如下所示

y1=tagit  y2=master
|         /
|        /
|       /
|      /
|     /
|    /
|   /
|  /
x

这似乎就像你的情况

于 2015-11-18T14:23:37.247 回答