简体   繁体   English

git copy [branch]中的文件,并粘贴到其他[branch or master]下

[英]git copy Files from [branch] and paste at under other [branch or master]

I created repository as following ..., 我创建存储库如下...,

TestRepo.git
    |
    |_[Branch.Master]
             |____________Master.txt
    |_[Branch.Develop]
             |____________Develop.txt

I want to copy Develop.txt and paste under [Branch.Master] . 我想复制Develop.txt并粘贴在[Branch.Master]

/// So I checkout Develop first.
$ git checkout Develop
/// Then I push develop.txt to remote/master
$ git push origin develop:master
/// Then I pull remote/master to my local/master.

Then I got below result which is not what I want. 然后我得到了低于我想要的结果。

TestRepo.git
    |
    |_[Branch.Master]
             |____________Develop.txt
    |_[Branch.Develop]
             |____________Develop.txt

What I want is like below. 我想要的是下面的样子。

TestRepo.git
    |
    |_[Branch.Master]
             |____________Master.txt
             |____________Develop.txt
    |_[Branch.Develop]
             |____________Develop.txt

I don't want to be replaced, what I want is just append. 我不想被替换,我想要的只是追加。

I appreciate your suggestion(s). 感谢您的建议。

If all you want to do is to add a new file, you can simply copy the file from the source branch to the target branch. 如果您要做的只是添加一个新文件,只需将文件从源分支复制到目标分支即可。

git checkout master
git checkout Develop Develop.txt

Then add the file, commit it, and push the branch out. 然后添加文件,提交并推出分支。

git add Develop.txt
git commit -m 'Added Develop.txt to the master branch'
git push origin master

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM