[英]Merge part of a branch into master with git
我將解釋我的情況:
master
, branch1
我的master
分支具有以下文件和與之關聯的提交-就像在我創建每個文件之后我都執行git commit
:
master-file1.html has masterfile1-commit-message master-file2.html - masterfile2-commit-message master-file3.html - masterfile3-commit-message
我的branch1
分支具有以下文件和與之關聯的提交:
branch1-file1.html has branch1file1-commit-message branch1-file2.html - branch1file2-commit-message branch1-file3.html - branch1file3-commit-message branch1-file4.html - branch1file4-commit-message branch1-file5.html - branch1file5-commit-message
所以我不想將branch1
完全合並到master
分支,我只想部分合並。 所以最終我想要的是這樣的:
我的master
分支應該是這樣的:
master-file1.html has masterfile1-commit-message master-file2.html - masterfile2-commit-message master-file3.html - masterfile3-commit-message branch1-file1.html has branch1file1-commit-message branch1-file2.html - branch1file2-commit-message
我的branch1
分支應該保持不變:
branch1-file1.html has branch1file1-commit-message branch1-file2.html - branch1file2-commit-message branch1-file3.html - branch1file3-commit-message branch1-file4.html - branch1file4-commit-message branch1-file5.html - branch1file5-commit-message
我可以在git中實現嗎? 如果是這樣,那又如何?
首先,使用branch1-file2.html
查找提交的SHA1哈希。 您可以使用以下命令執行此操作:
git checkout branch1
git log --oneline
在每行的開頭查找十六進制字符串。 現在,一旦有了哈希,就可以將master
合並到其中:
git checkout master
git merge <SHA1 hash>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.