git push origin HEAD:myBranch --force
。总的来说,这很好用也很有帮助。 - ScottyBladesgit rebase -i HEAD~<n>
之后,在文件顶部将会有<n>行提交记录,每行都包含文本pick <commit id>
。这些提交默认为pick
,因此如果您想要删除某个提交,只需将文本pick
更改为drop
即可。 - Slim你有几种方法可以做到这一点。
这篇帖子 - 阅读关于还原的部分将详细解释我们想要做什么以及如何做到它。
以下是最简单的解决方案:
# Checkout the desired branch
git checkout <branch>
# Undo the desired commit
git revert <commit>
# Update the remote with the undo of the code
# The force is a tricky flag since it will force the push but
# your administrator can block it, so if it's not an option you
# can delete the old branch and push it again
git push origin <branch> --force
revert 命令将创建一个新提交,其中包含原始提交的撤销。
git revert <Merge pull request commit id> -m 1
- Techie-m n
而不是 1。 - CodeWizardgit revert <commit>
命令后使用 git push --force
。这将撤销 Pull Request 上的提交。 - undefinedpush --force
可能被 Git 管理员禁用 - undefined如果你要删除一个提交并且不想保留它的更改,@ferit提供了一个好的解决方案。
如果你想将该提交添加到当前分支中,但它不应该成为当前pr的一部分,可以采取以下步骤:
git rebase -i HEAD~n
git reset HEAD^ --soft
撤销提交并将更改重新放回暂存区。git push --force
更新远程分支,但不包括你已删除的提交。现在你已经从远程仓库中删除了该提交,但在本地仍然保留更改。
git push --force
命令时一定要非常小心。它会完全(且不可逆地)用本地计算机的内容覆盖远程仓库上的所有内容。 - Velociround以下是帮助我解决问题的方法:
创建一个新分支用于覆盖已有分支,我们称之为现有分支 branch_old
和新分支为 branch_new
。
将 branch_new
重置到稳定状态,即当您没有任何问题提交时所处的状态。
例如,要将其放在本地主分支的级别上,请执行以下操作:
git reset —hard master git push —force origin
使用 cherry-pick
命令将提交从 branch_old
合并到 branch_new
上。
git push
请在您的分支下运行以下命令:
git reset --soft origin/master
git commit -m "Detail of Your last commit that you want to see"
git push -f
请按照以下步骤操作:
假设您的分支名称是my_branch,并且有额外的提交。
git checkout -b my_branch_with_extra_commits
(将此分支保存为不同的名称)gitk
(打开git控制台)git checkout my_branch
gitk
(这将打开git控制台)git pull --rebase origin branch_name_to_merge_to
git cherry-pick <在第3步中复制的SHA>
现在查看本地分支提交历史记录,确保一切正常。
1. git reset <commit ID wherever you want to jump>
2. git restore <file name you want to remove> or git add <all the file
names you want to add to commit>
3. git commit -m “new commit message”
4. git push -f //necessary to push forcefully (if anything is there to pull)