Nag*_*ran 3 git merge github git-merge
我有两个名为A和B的git本地分支(指向远程分支原点/ A和原点/ B).
Branch - A:
Folder-1
File-11
File-12
Folder-2
File-21
File-22
Branch - B:
Folder-2
File-22
File-23
Folder-3
File-31
File-32
Run Code Online (Sandbox Code Playgroud)
我想将分支B与分支A合并.
git checkout A
git merge B
Run Code Online (Sandbox Code Playgroud)
最终的结果应该是这样的.
Branch - A:
Folder-1
File-11
File-12
Folder-2
File-21
File-22 (Branch -A file).
Folder-3
File-31
File-32
Run Code Online (Sandbox Code Playgroud)
仅合并文件夹-3,将文件夹-1和文件夹-2保留在分支A中.
基本要求是,我不应该丢失日志(和提交)历史记录.
怎么做?
提前致谢.
如果您只想将Folder-3分支的内容添加B到分支A,并且不关心使此提交成为合并提交,则这是一种简单的方法:
# from branch A :
git checkout A
# say "get me the content of Folder-3 from branch B" :
git checkout B -- Folder-3/
# and commit this new content on top of branch A :
git commit
Run Code Online (Sandbox Code Playgroud)
如果要将提交标记为合并提交,请执行以下操作:
# from branch A :
git checkout A
# say "start a merge commit, I initially want to only keep the content of A" :
git merge -s ours --no-commit B
# -s ours : keep current branch content (current branch is A)
# --no-commit : do not run the 'git commit' command yet, I will do it later
# say "get me the content of Folder-3 from branch B" :
git checkout B -- Folder-3/
# and commit this new content on top of branch A :
git commit
Run Code Online (Sandbox Code Playgroud)
git checkout B
git add Folder-3
git add Folder-2/File-23
git checkout -- Folder-2/File-22
git comit -m "add Folder-3"
git checkout A
git merge B
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2435 次 |
| 最近记录: |