简体   繁体   English

如何使用 git 将文件从一个分支复制到另一个分支?

[英]How can I copy files from a branch to another using git?

I have a git repository with two branches: master and gh-pages .我有一个带有两个分支的 git 存储库: mastergh-pages If I want to copy a file foo from master to gh-pages without merging them.如果我想将文件foomaster复制到gh-pages而不合并它们。 What command should I use?我应该使用什么命令? Many thanks.非常感谢。

You can:你可以:

git checkout gh-pages
git checkout master foo
git commit -m 'Add file foo to gh-pages.'

If you want to compare all the diffs between 2 branches: you can use git difftool master gh-pages or git difftool <SHA1 of gh-pages> .如果您想比较 2 个分支之间的所有差异:您可以使用git difftool master gh-pagesgit difftool <SHA1 of gh-pages> .

If you want to get diff for specific list of files follow this :如果您想获取特定文件列表的差异,请遵循以下步骤

git diff master gh-pages -- path/to/file

也可以在提交foo后从mastergh-pages进行cherry-pick。(在cherry-pick 之后必须执行git add [path to foo]并提交)

The Way I would do it: When you commit you have a choice of what to commit and push.我会这样做:当你提交时,你可以选择提交和推送什么。 So commit only foo from master then push it, Then just merge that on github/bitbucket whatever to gh-pages所以只从master提交foo然后推送它,然后在 github/bitbucket 上将它合并到gh-pages

暂无
暂无

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

相关问题 如何将所有文件和文件夹从一个分支替换/复制到GIT中的另一个现有分支 - How Can I replace/copy all file and folder from one branch to another existing branch in GIT 如何在git中将文件从一个分支合并到另一个分支? - How can I merge files from one branch to another branch in git? 当存在不共享的文件时,如何从另一个分支更新 git 分支? - How can I update a git branch from another branch when there are files that do not share? 我怎样才能使git保留另一个分支文件 - How can i make git keep another branch files Git钩子-如何将文件从一个文件夹复制到同一git分支内的另一个文件夹 - Git hooks - How to copy files from one folder to another folder within same git branch 如何将许多扩展名定义的文件从一个远程存储库分支复制到另一个文件夹中的许多文件夹中? - How can I copy many files, defined by extension, in many folders, from one remote repository branch to another? Git:如何从远程分支中排除某些文件,然后将它们包含在另一个分支中? - Git: How can I exclude certain files from a remote branch and include them in another? 如何在 Git 中将一些文件(不是全部)从一个分支移动到另一个分支? - How can I move some files (not all) from one branch to another in Git? Git:将组文件从一个 Git 分支复制到另一个 Git 分支? - Git: Copy a Group files from one Git Branch into Another Git branch? 将所有文件从master复制到git中的另一个分支 - Copy all files from master to another branch in git
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM