GIT:修改secondlast推送提交的内容

时间:2017-03-17 10:08:10

标签: git

如何使用GIT修改第二个最后推送的提交,我需要从提到的提交中删除一些文件,我想保留最后一次提交。

到目前为止我做了什么:

onPostExecute

1 个答案:

答案 0 :(得分:2)

您需要做的是要修改的提交的 rebase

<强>步骤:

  1. 获取要修改的提交的提交ID

    git log -2 // here '2' => will display last 2 commits
    // lets say the commit you wish to change has ID "ededeac"
    
  2. 执行交互式 重新安装

    git rebase --interactive ededeac // where "ededeac" is the commit to modify
    

    将出现一个编辑器,其中列出了自您提交的所有提交以来的所有提交。 对于需要修改的提交,请将pick更改为 edit

    pick 8c27d78 fixed some bug
    edit ededeac fixed another bug // here, we changed pick to edit
    

    保存并退出。然后Git将重播列出的提交。

    对于您要编辑的每个提交,Git会将您带入shell。然后,您可以以任何您喜欢的方式更改提交。

    // delete/update files
    git commit --all --amend //here you can change the commit message too
    // The new changes are added on to the old commit
    // You can verify that with 'git log' and 'git diff HEAD^'
    git rebase --continue
    
  3. 强制推送到原点。

    git push origin --force-with-lease
    

    您需要强制推送到原点,因为您重写历史记录

相关问题