为什么我的新 Git 分支不为空?
假设我们从一个全新的设置开始。
touch somefile
git init .
git add .
git commit -m "initial commit"
git branch dev
git checkout dev
在执行git status
之后,我得到了
nothing to commit (working directory clean)
在执行git merge master
之后,我得到了
Already up-to-date.
为什么是这样?我认为新分支开始时是干净的(并且是空的),直到我们直接添加内容或从现有分支合并。
Suppose we start with a brand new setup.
touch somefile
git init .
git add .
git commit -m "initial commit"
git branch dev
git checkout dev
After doing git status
, I get
nothing to commit (working directory clean)
After doing git merge master
, I get
Already up-to-date.
Why is that? I thought new branch starts clean (and empty) until we either add content directly or merge from existing branch.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
发布评论
评论(3)
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
Git 中的分支只不过是指向提交的指针。当您像以前那样创建分支时,它指向与其他分支相同的提交。一旦你提交了一些东西,你就会发现它们有所不同。大多数其他版本控制系统不适用于此类基于快照的方法。
因此,当您发出合并命令时,它没有任何可合并的内容,因为您当前的分支已经包含其他分支的所有提交。
我强烈建议阅读 progit.org/book 并充分理解历史结构遵循的 DAG(有向无环图)。
希望这有帮助。
Branches in Git are nothing more than pointers to commits. When you create a branch as you did, it is pointing to the same commit as the other branch. Once you commit something after that is when you will see them differ. Most other version control systems don't work on snapshot-based approaches like this.
Thus, when you issue the merge command, it has nothing to merge as your current branch already contains all the commits of the other branch.
I would highly recommend reading progit.org/book and fully understanding the DAG (directed acyclic graph) that the history structure follows.
Hope this helps.