gpt4 book ai didi

Git merge : keep only the staged commits and toss the rest?

转载 作者:太空狗 更新时间:2023-10-29 13:42:55 25 4
gpt4 key购买 nike

在进行 merge/ rebase 时,我经常遇到这种情况: - 遇到一些冲突 - 解决重要的问题,将它们移动到索引

然后,有一堆未暂存的垃圾,我只想保留 HEAD 版本。理想情况下,我可以只执行“git commit && git reset --hard”,但 git 不会让我在仍有未 merge 的待处理内容时提交。我试过“git stash save --keep-index”但是失败了。我尝试了“git diff | patch -Rp1”(以及各种突变)。我认为任何“git reset”模式都不符合我的要求。

一定有一种方法可以说“我得到了我想要的,只需丢弃其余部分”。

最佳答案

没有开箱即用的解决方案,但您可以创建一个别名。

您可以使用:

git checkout HEAD -- <list of files to keep as HEAD>

指定您希望保留给定文件,因为它们在 HEAD 中。

要获取剩余冲突的列表,您可以使用:

git diff --name-only --diff-filter=U

然后将其作为别名放在一起:

alias gitkeeprest="for file in $(git diff --name-only --diff-filter=U); do git checkout HEAD -- $file; done"

有了它,您将:

  • 照常开始 merge 。
  • 解决您感兴趣的部分将其添加到索引中。
  • 通过运行 gitkeeprest 将其余部分恢复为 HEAD 版本。

关于Git merge : keep only the staged commits and toss the rest?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35108857/

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