Git从另一个分支复制文件而不暂存

标签 git

我已经 found如何将文件从一个分支批量复制到另一个分支:

Edit please note, if you think this question is a duplicate of this, please observe that that's the question I linked above^^, and what follows below explains the different functionality that I want.


$ 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/

相关文章:

django - 推送Django项目时Heroku上出现 "Push rejected, no Cedar-supported app detected"如何解决?

django - git aws.push : No module named boto

Eclipse git 无法完成 rebase

git - 如何在私有(private) GitLab 存储库中使用 Go

git - 如何镜像Github和VS Online?

javascript - Gulp 失败并返回 Unhandled 'error' 事件

git - 使用 git 版本控制仅更新和提交文件的权限

node.js - 将 Node 模块 checkin Git 中以获取新分支

git 初始化远程仓库

git - git 如何管理冲突的差异?