更新时间:2023-11-28 07:52:03
您希望文件最终到达的分支:
git checkout otherbranch myfile.txt
通用公式:
git checkout< ; commit_hash> < relative_path_to_file_or_dir>
git checkout< remote_name> /< branch_name> < file_or_dir>
一些注释(来自评论):
myfile.txt
和 mydir
替代方案:
git show commit_id:path / to / file> path / to / file
I've got two branches that are fully merged together.
However, after the merge is done, I realise that one file has been messed up by the merge (someone else did an auto-format, gah), and it would just be easier to change to the new version in the other branch, and then re-insert my one line change after bringing it over into my branch.
So what's the easiest way in git to do this?
Run this from the branch where you want the file to end up:
git checkout otherbranch myfile.txt
General formulas:
git checkout <commit_hash> <relative_path_to_file_or_dir>
git checkout <remote_name>/<branch_name> <file_or_dir>
Some notes (from comments):
myfile.txt
and mydir
an alternative:
git show commit_id:path/to/file > path/to/file