我做了一个拉请求,但之后我在本地对项目进行了一些提交,最终污染了我的拉请求,我试图删除它,但没有任何运气。
我在StackOverflow上找到了一些类似的问题,但我不能应用那里的内容。 这是我在GitHub上的第一个拉请求,所以对我来说这一切是如何工作的有点奇怪。
突出显示的提交是我需要保留并删除所有其他内容的提交。 它变成了历史上的第四次提交因为我做了一些合并的东西。
我的git日志
有人能解释一下发生了什么以及如何解决这个问题吗?
我做了一个拉请求,但之后我在本地对项目进行了一些提交,最终污染了我的拉请求,我试图删除它,但没有任何运气。
我在StackOverflow上找到了一些类似的问题,但我不能应用那里的内容。 这是我在GitHub上的第一个拉请求,所以对我来说这一切是如何工作的有点奇怪。
突出显示的提交是我需要保留并删除所有其他内容的提交。 它变成了历史上的第四次提交因为我做了一些合并的东西。
我的git日志
有人能解释一下发生了什么以及如何解决这个问题吗?
当前回答
你有好几种方法可以做到。
这篇文章-阅读关于恢复的部分将详细解释我们想做什么以及如何做。
这里有一个最简单的解决方法:
# 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命令将使用原始提交的undo命令创建一个新的提交。
其他回答
这对我很有帮助:
用现有的分支创建一个新的分支。让我们将现有的branch_old和new分别称为branch_new。 将branch_new重置为稳定状态,当你提交时没有任何问题。 例如,要将其设置为本地master级别,请执行以下操作: Git复位-硬主 Git push -force origin 从branch_old选择提交到branch_new git推
从你的分支开火以下命令
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(保持这个分支保存在不同的名称下) 打开git控制台 寻找你想要兑现的承诺。将该提交的SHA复制到记事本。 Git签出my_branch gitk(这将打开git控制台) 右键单击要恢复的提交(更改前的状态),然后单击“重置分支到这里” 做一个git拉——rebase origin branch_name_to _merge_to git选择<SHA你复制在步骤3。>
现在查看本地分支提交历史并确保一切正常。
你有好几种方法可以做到。
这篇文章-阅读关于恢复的部分将详细解释我们想做什么以及如何做。
这里有一个最简单的解决方法:
# 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命令将使用原始提交的undo命令创建一个新的提交。
如果不小心推送了不必要的文件,并希望将它们从PR中删除
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)