gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 11:13:45 25 4
gpt4 key购买 nike

我已经 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com