本文介绍了如何将单个文件的版本从一个git分支复制到另一个分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



然而,在合并完成之后,我意识到一个文件被合并搞乱了(其他人做了一个自动格式化,gah),并且在另一个分支中更改为新版本会更容易,然后在将其更改到我的分支后重新插入我的一行更改。



那么在git中最简单的方法是做什么?

解决方案

您希望文件最终到达的分支:

  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):

  • Using the commit hash you can pull files from any commit
  • This works for files and directories
  • overwrites the file myfile.txt and mydir
  • Wildcards don't work, but relative paths do
  • Multiple paths can be specified

an alternative:

git show commit_id:path/to/file > path/to/file

这篇关于如何将单个文件的版本从一个git分支复制到另一个分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 06:50