found如何将批发的文件从一个分支复制到另一个分支:


$ 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 show然后重定向...虽然不是很优雅

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

关于从另一个分支Git复制文件而不进行暂存,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56029523/

10-14 22:58
查看更多