标题,基本上。这似乎是构建提交的首选资源。我在官方书籍中找不到描述这个主题的文章,所以如果我错过了,请指出我的方式。
我的问题是关于没有父母的提交,即初始提交。具体来说,在不存在父提交的情况下,什么会被散列?并且,什么时候需要父提交?是否可以在没有父母的情况下进行多次提交?
在我的实验中,我发现在第一次提交之前,不存在任何分支;考虑到分支是提交的引用,而且还不存在,这是有道理的。
您想要多少都可以!
一次提交不必只有一个父提交。它可以有任意数量的父母!
进行章鱼合并看起来就像常规合并一样,只是有更多参数。
常规合并:
# merge branch1 into current branch
git merge branch1
Run Code Online (Sandbox Code Playgroud)
章鱼合并:
# Merge branches 1, 2, and 3 into the current branch
git merge branch1 branch2 branch3
Run Code Online (Sandbox Code Playgroud)
如果您想一次合并一堆单独的功能分支,它会很有用。
git switch main
git merge feature-1 feature-2 feature-3 feature-4
Run Code Online (Sandbox Code Playgroud)
这在历史记录中看起来更清晰,因为您只有一次合并提交,而不是连续的一大堆合并提交。
当合并冲突的可能性非常低时最好使用它。
在 Linux 内核中的 66 路合并的情况下,它们合并了对一堆单独驱动程序的更新,因此分支之间不存在冲突。
基本上,一切。
这意味着如果您更改提交消息(例如,使用git commit --amend),您将更改提交哈希,因此该提交将显示为不同的提交
是的!Git 可以做任何事情!有两种方法可以在没有父母的情况下进行多次提交:
您可以通过创建一个孤立分支git switch --orphan <new branch name>,这将创建一个空的孤立分支。
注意:要将其合并到具有不相关历史记录的存储库,只需执行以下操作:
# Add a separate repo as a remote
git remote add other-repo <other-repo-url>
# Fetch the contents of that repo
git fetch other-repo
# Merge the main branch of the other repo into your repo
git merge --allow-unrelated-histories other-repo/main
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
479 次 |
| 最近记录: |