Git 分支仍然与主分支在同一行

Git branch is still on same line as master

我在 git 树中发生了一些意想不到的事情。我已经在 master 之外创建了一个分支,但是当我在新分支上执行提交时,这些提交似乎发生在与 master 相同的代码行中...

如您所见,最左侧是 master 的代码行(深蓝色),在顶部我们可以看到 Sprint_15 这是从 master 中提取的一个分支,看起来有在同一行上提交...我不确定为什么会这样。我希望看到代码分叉成一个新行,因为功能正在合并到 Sprint_15 而不是 master...

我的想法是,通过将 Sprint_14 和 Sprint_15 合并在一起,这对历史做了一些时髦的事情,但我不确定为什么。

我对 git 还是很陌生,所以它的一些基础仍然让我感到困惑。

这是一个推测,但我建议您当前的功能分支似乎与 master 在同一行的原因是因为当前该分支直接领先于 master 一些数字提交。要对此进行测试,请尝试拉取最新的 master 分支。如果这改变了您的配置,使 Sprint_15 显示为单独的一行,那么我的预感是正确的。

无论如何,如果您有疑问,可以随时直接从 Git bash 中查看此类内容。

看来您对 git 的工作方式有点误解(这很正常,因为您说您是 git 的新手)

每个分支不一定都有自己的线路。如果您的分支 Sprint_15 的基础是 master 并且 Sprint_15master 之前的任意数量的提交,那么它们将共享同一行。一旦 master 得到一个新的提交,我想你就会看到你所期望的。

您可以像这样在单独的 git 存储库中测试它。

$ mkdir testing && cd testing
$ git init  # should put you on master branch by default
$ touch testFile.txt
$ git add -A
$ git commit -m "initial commit"
$ git branch newBranch
$ git checkout newBranch # switch from master to newBranch

### modify the testFile.txt in some way and then...
$ git add -A
$ git commit -m "first commit on newBranch"

现在,如果您使用相同的工具查看您的存储库,您应该只会看到一行,如下所示:

现在回到master分支再做一次提交:

$ git checkout master
### make another change to testFile.txt
$ git add -A
$ git commit -m "second commit on master"

现在您会看到每个分支都有自己的行,就像您期望的那样: