git revert commit/push 但保留更改

标签 git commit revert

它是这样的:

  • 我修改了文件 A 和 B

  • 我只打算提交并推送 A,但不小心同时提交并推送了 A 和 B

  • 我做了一个“git push old-id:master”所以在 github 上它显示“Master is now old-id”其中 old-id 是我之前的最后一次提交,所以我认为它回到了我之前 promise 。

问题:

  • 在我的本地,我如何撤消具有 A 和 B 的提交,并仅提交 A,并仅推送 A?

注意:不过,我确实需要在本地保留 A 和 B 的更改。最终结果应该是:

  • 本地 - 新 A 和新 B
  • Github - 新 A 和旧 B

最佳答案

$ git reset <old-id>    # Undo the commit after old-id
$ git add A             # stage A for a new commit
$ git commit            # make the new commit
$ git push              # push it

关于git revert commit/push 但保留更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10184637/

相关文章:

git lfs prune 从 lfs 中删除文件并推送到源

git - 创建获取最后一次提交的 Git 别名

github - 在 GitHub for Windows 中还原此提交并回滚此提交是什么意思?

git - 查找 Git 提交来自哪个分支

git - 从 TeamCity 中的分支名称中删除斜线

git - 检查 git 中的重复文件(内容)?

git - 为什么有些 git commits 比它们的父级更旧?

python - 在 Django 中使用 MySQLdb 的 MySQL 响应中的缓存问题

html - 有没有办法设置HTML5拖拽结束效果? (即不恢复)

git:更好的 git revert 方法,无需额外的还原提交