如何从其他分支上的本地提交复制文件? [英] How can i copy a file from local commit on a different branch?
问题描述
我在 master
分支上提交了一个文件,但未推送 remote
.现在,我正在 feature
分支上工作,我希望将该文件从 master
分支复制到 feature
分支.
I committed a file on master
branch but not pushed remote
. Now i am working on feature
branch and i want that file to be copied to feature
branch from master
branch.
我该怎么做?
推荐答案
您可以从另一个分支签出特定文件:
You can checkout a specific file from another branch:
git checkout master -- path/to/file
该文件将按原样从分支 复制到工作树中,并自动上演.
The file will be copied from the branch as is into the working tree, and automatically staged.
请注意,从工作树根开始的相对路径很重要.例如,如果您位于工作树的根目录(在 .git
目录中),则分支中文件的路径也必须相对于存储库根目录是相对的.如果您在子目录中,请进行相应的调整.
Note that the relative path from the working tree root is important. For example if you are in the root of the working tree (where there is the .git
directory), then the path to the file in the branch must also be relative from the repository root. If you are in a subdirectory, then adjust accordingly.
要验证正确的路径, ls-files
命令可能会有所帮助,例如:
To verify the correct path, the ls-files
command can be helpful, for example:
git ls-files --with-tree master | grep file
这篇关于如何从其他分支上的本地提交复制文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!