将所有文件从master复制到git中的另一个分支

时间:2015-10-14 04:27:50

标签: git

我只需将master分支中的所有文件复制到production分支,然后在那里生成缩小代码等,并在production中进行检查。

我不想合并但只复制文件。

我试图在谷歌搜索,但我很困惑。

我遵循这种粗俗的方法:

#currently I'm in master branch in current directory
rm -rf /tmp/production
cp -r . /tmp/production
rm -rf /tmp/production/.git
git checkout production
cp -r /tmp/production/* .

是否有任何单行命令?

3 个答案:

答案 0 :(得分:0)

git checkout master
cp -r . /tmp/production
rm -rf /tmp/production/.git
git checkout production
cp -r /tmp/production/* ./copy_of_production

我想是的。

答案 1 :(得分:0)

您可以重复使用" How can I overwrite, not merge, one remote branch into another branch?"

中的方法
git checkout production     # First, merge master into production so we have
git merge -s theirs master  # a merge commit to work with.

git checkout master         # Then, flip back to master's version of the files

git reset --soft production # Then we go back to the merge commit SHA, but keep 
                            # the actual files and index as they were in master

git commit --amend          # Finally, update the merge commit to match the
                            # files and index as they were in master.

这不是一行,但确实记录了master覆盖production内容的事实。

答案 2 :(得分:-1)

你可以做的很简单的事情就是当你创建分支生产时,你将定位为掌握然后你可以推动原产地。

示例:

git checkout -b production //to create branch production
git checkout master // to be positioned on the master 
git push origin production