我有两个名为A和B的git本地分支(指向远程分支origin/A和origin/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我想合并分支B和分支A。
git checkout A
git merge B最终的结果应该是这样的。
Branch - A:
Folder-1
File-11
File-12
Folder-2
File-21
File-22 (Branch -A file).
Folder-3
File-31
File-32单独合并文件夹-3,保留分支A中的文件夹-1和文件夹-2。
基本要求是,我不应该丢失日志(和提交)历史记录。
该怎么做呢?
提前谢谢。
发布于 2016-03-10 18:52:49
如果您想将提交标记为合并提交,这里有一种方法:
# 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使用此选项:分支B将被标记为合并到A中,您将看到提交的历史记录:
$ git log --oneline --graph A
* aa1234 (HEAD -> A) Merged branch 'B' into A
|\
| * bb1234 (B) update 3 on branch B
| * cc1234 update 2 on branch B
| * dd1234 update 1 on branch B
...如果您只想将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发布于 2016-03-10 18:38:21
试试这个:
$ git checkout branchB
$ git checkout -b branchC
$ rm -rf folderA and folderB //pseudocode. Remove folder A and B
$ git checkout branchA
$ git merge branchC
$ git add -A
$ git commit -m "Added folderC"
$ git push
$ git branch -d branchC发布于 2016-03-10 18:11:26
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 https://stackoverflow.com/questions/35913270
复制相似问题