GIT:修改第二次推送提交的内容

GIT:修改第二次推送提交的内容,git,Git,如何使用GIT修改最后一次推送的第二次提交,我需要从提到的提交中删除一些文件,并且我希望保留最后一次提交 到目前为止我所做的: git reset --soft HEAD^ git reset --soft HEAD^ # two times git reset HEAD .idea/ # and the same for other directories git add -A git commit --amend 您需要做的是重新设置要修改的提交的基础 git log -2 //

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

到目前为止我所做的:

git reset --soft HEAD^
git reset --soft HEAD^   # two times

git reset HEAD .idea/  # and the same for other directories

git add -A
git commit --amend

您需要做的是重新设置要修改的提交的基础

git log -2 // here '2' => will display last 2 commits
// lets say the commit you wish to change has ID "ededeac"
步骤:

  • 获取要修改的提交的提交ID

    git log -2 // here '2' => will display last 2 commits
    // lets say the commit you wish to change has ID "ededeac"
    
  • 进行交互式的重新设置基础

    git rebase --interactive ededeac // where "ededeac" is the commit to modify
    
    将出现一个编辑器,其中列出自您提交以来的所有提交。 将需要修改的提交更改为
    选择
    编辑

    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
    
  • 强制推至原点

    git push origin --force-with-lease
    
    您需要强制推送到原点,因为您正在重写历史


  • 第二步中的可能重复:
    git-rebase--interactive“hash of the 2 commit”
    在编辑器中,我只得到一个commit(对应于第一个commit,第二个不存在)
    选择8c27d78 blabla
    @JaouharMbarek,这可能是因为您选择的提交ID不正确。请尝试
    git log-10
    查看最近10次提交,然后使用所需的提交ID重试。