標題,基本上。這似乎是構建提交的首選資源。我在官方書中找不到描述這個主題的文章,所以如果我錯過了,請指點我。
我的問題是關于沒有父母的提交,即初始提交。具體來說,在不存在父提交的情況下會散列什么?而且,什么時候需要父提交?是否可以在沒有父母的情況下進行多次提交?
在我的實驗中,我看到在第一次提交之前,不存在任何分支;考慮到分支是對提交的參考,并且尚不存在,這是有道理的。
uj5u.com熱心網友回復:
系好安全帶,bxtches,因為今天我們談論的是提交!
一個提交可以有多少個父母?
你想要多少就多少!
提交不必只有一個父級。它可以有任意數量的父母!
- 初始提交有 0 個父項
- 正常提交有 1 個父級
- 合并提交通常有 2 個父項...
- 但是 Octopus 合并可以導致任何數量的父項提交(Linux 內核有 66 個父項的提交,這是 66 路合并的結果!技術術語是 cthlulhu 合并。)
進行章魚合并看起來就像常規合并,只是有更多的引數。
常規合并:
# merge branch1 into current branch
git merge branch1
八達通合并:
# Merge branches 1, 2, and 3 into the current branch
git merge branch1 branch2 branch3
為什么要經歷章魚合并的恐怖?
如果您想一次合并一堆單獨的功能分支,它會很有用。
git switch main
git merge feature-1 feature-2 feature-3 feature-4
這在歷史記錄中看起來更清晰,因為您只有一個合并提交,而不是連續的一大堆合并提交。
當合并沖突的可能性非常低時,最好使用它。
在 linux 內核中的 66 路合并的情況下,它們合并更新到一堆單獨的驅動程式,因此分支之間沒有沖突。
在初始提交中散列的內容
基本上,一切。
- 作者和作者的電子郵件
- 添加到初始提交的任何檔案或目錄
- 提交訊息
這意味著如果您更改提交訊息(例如,使用git commit --amend),您正在更改提交哈希,因此提交顯示為不同的提交
是否可以在沒有父母的情況下進行多次提交?
是的!Git可以做任何事情!有兩種方法可以在沒有父項的情況下進行多次提交:
- Merge in an unrelated repository with it's own history (this has happened 3 times in the history of the linux kernel)
- Create an orphan branch (this is a branch that doesn't share history with any other branch)
You can create an orphan branch via git switch --orphan <new branch name>, which will create an empty orphan branch.
Note: to merge it a repository with an unrelated history, just do:
# 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
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/346807.html
標籤:混帐
