问题
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.
How can i do this?
回答1:
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.
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.
To verify the correct path, the ls-files
command can be helpful, for example:
git ls-files --with-tree master | grep file
来源:https://stackoverflow.com/questions/37203545/how-can-i-copy-a-file-from-local-commit-on-a-different-branch