git - 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 show 然后重定向......虽然它不是很优雅
git show feature-B:directory/somefile.php > directory/somefile.php
推荐阅读
- node.js - Websocket 请求有时在连接建立后不起作用
- django-models - 我可以多次使用同一个外键吗?
- java - 在 Spring MVC + Postgres 上访问列元数据时出错
- momentjs - 使用 moment/moment-timezone 将时间从其他时区转换为本地时区
- azure-sql-database - 从本地网络性能访问 Azure SQL 数据库
- python - 在 python 3.7 中导入熊猫时出错
- laravel - Laravel PWA Service Worker 添加问题
- image - 私有 docker 注册表文件夹结构
- php - 从 codeigniter 函数检索和显示 json 数据
- xml - 当实际编码和标签不一致时,XML 文件是否存在预期行为?