簡體   English   中英

使用git將分支的一部分合並到master中

[英]Merge part of a branch into master with git

我將解釋我的情況:

  1. 我有兩個git分支說masterbranch1
  2. 我的master分支具有以下文件和與之關聯的提交-就像在我創建每個文件之后我都執行git commit

     master-file1.html has masterfile1-commit-message master-file2.html - masterfile2-commit-message master-file3.html - masterfile3-commit-message 
  3. 我的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分支,我只想部分合並。 所以最終我想要的是這樣的:

  1. 我的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 
  2. 我的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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM