【问题标题】:git selective revert (equivalent of `git revert --patch`)git 选择性恢复(相当于`git revert --patch`)
【发布时间】:2017-12-29 06:37:18
【问题描述】:

是否有一种首选的方法来恢复先前提交的部分内容,例如部分恢复未暂存的更改 (git checkout -p) 和部分添加未暂存的更改 (git add -p)?

即我有几个(甚至很多)提交,其中包含想要的和不需要的更改,我想有选择地还原其中一些更改,同时保留其他更改。

我目前的工作流程并不有趣:

git diff commit commit^ > selective.diff
cp selective.diff selective2.diff
nvim selective2.diff 
# change unwanted - to ' ' and remove unwanted +, then save
rediff selective.diff selective2.diff | rewrite selective2.diff
git apply selective2.diff

并祈祷补丁能够成功

【问题讨论】:

    标签: git git-revert


    【解决方案1】:
    git revert --no-commit
    git reset --patch     # or `git checkout --patch` if you're sure
    

    【讨论】:

    • 你能添加更多的cmets吗?例如,我应该将提交的哈希放在哪里?
    【解决方案2】:

    我只能想到类似的东西

    git revert commit --no-commit
    git reset # now the changes are unstaged
    git add -p
    ...
    git commit
    

    但是我不知道它是否比您的解决方案更实用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-09
      • 2015-09-02
      • 1970-01-01
      • 2018-11-22
      • 2021-01-22
      • 1970-01-01
      • 2014-09-03
      • 2020-05-13
      相关资源
      最近更新 更多