我有一个名为app.js的主分支。我在一个实验分支上对这个文件进行了更改。
我只想将实验中对app.js所做的更改应用到master分支。
我有一个名为app.js的主分支。我在一个实验分支上对这个文件进行了更改。
我只想将实验中对app.js所做的更改应用到master分支。
当前回答
git checkout branch_name file_name
例子:
git checkout master App.java
如果分支名称中有句点,则此操作将不起作用。
git checkout "fix.june" alive.html
error: pathspec 'fix.june' did not match any file(s) known to git.
其他回答
要从另一个分支恢复文件,只需使用工作分支中的以下命令:
git restore -s my-other-branch -- ./path/to/file
-s标志是source的缩写,即要从中提取文件的分支。
(所选的答案信息量很大,但也有点令人难以理解。)
git checkout <branch_name> -- <paths>
更多信息
一切都简单多了,用git结账。
假设您在master分支上,要从新功能分支获取app.js,请执行以下操作:
git checkout new-feature path/to/app.js
// note that there is no leading slash in the path!
这将为您带来所需文件的内容。您可以像往常一样,使用sha1的一部分而不是新的功能分支名称来获取特定提交中的文件。
注意:新功能需要是本地分支,而不是远程分支。
git checkout master -go to the master branch first
git checkout <your-branch> -- <your-file> --copy your file data from your branch.
git show <your-branch>:path/to/<your-file>
希望这对你有所帮助。如果你有任何疑问,请告诉我。
如果您想要来自特定提交(任何分支)的文件,请说06f8251f
git checkout 06f8251f path_to_file
例如,在Windows上:
git checkout 06f8251f C:\A\B\C\D\file.h