首页 > 解决方案 > Git 从另一个分支复制文件而不暂存它

问题描述

发现了如何将文件从一个分支批量复制到另一个分支:

编辑请注意,如果您认为此问题与此问题重复请注意这是我在上面链接的问题^^,下面的内容解释了我想要的不同功能。

$ git checkout directory/somefile.php feature-B

但是,此解决方案已经对更改进行了分阶段:

$ git status
On branch feature-A
Your branch is up-to-date with 'origin/feature-A'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   directory/somefile.php

但我不想添加所有更改。我想做一个add -p并采取大部分但不是全部的更改。我想要的是这样的:

$ git status
On branch feature-A
Your branch is up-to-date with 'origin/feature-A'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   directory/somefile.php

no changes added to commit (use "git add" and/or "git commit -a")

当然,我可以git reset取消暂存更改,但我想第一次得到我想要的,没有第二步。

如何在不暂存的情况下从另一个分支复制文件?

标签: git

解决方案


你可以使用 git show 然后重定向......虽然它不是很优雅

git show feature-B:directory/somefile.php > directory/somefile.php

推荐阅读