从现有拉取请求中删除提交
Remove commits from an existing pull request
我在 Github 上分叉了一个项目,进行了提交,推送到我的分叉并提出了拉取请求。一切都很好。
然后,我一直在提交和推送不相关的东西,却没有意识到所有这些都会添加到我的拉取请求中。
我需要保留我在分叉中所做的更改(在不同的分支或其他地方),但我必须从拉取请求中删除除第一个提交之外的所有更改。我该怎么做?
首先,确保您当前的工作树是干净的,然后在最后一次提交时创建一个新分支以确保您不会丢失您的工作:
git stash
git checkout -b unrelated-stuff
现在,您切换回拉取请求分支:
git checkout feature
然后您重置分支以指向特定的提交 ID(您将通过 git log
或通过任何 GUI 应用程序找到该 ID):
git reset --hard COMMIT_ID
一旦您的本地 feature
分支指向您喜欢的提交,您可以将该分支强制推送到服务器:
git push --force
此时,您在服务器上的拉取请求将仅包含相关提交,不相关的工作仍然在 unrelated-stuff
分支上可用。
如果您在 git stash
编辑之前有任何未保存的工作,您可以使用 git stash pop
找回它。
Please note that force-pushing is a highly discouraged operation in git, because it could break other people's local repositories. It should be generally ok in the context of pull requests (many repo owners prefer merging PRs only when they are clean and tidy after reviewing), but never ever force-push into master or other branches where there is potential that other people are working on.
理解和学习 git 的重要资源是 http://learngitbranching.js.org - 如果您有兴趣,请看一看!
我在 Github 上分叉了一个项目,进行了提交,推送到我的分叉并提出了拉取请求。一切都很好。
然后,我一直在提交和推送不相关的东西,却没有意识到所有这些都会添加到我的拉取请求中。
我需要保留我在分叉中所做的更改(在不同的分支或其他地方),但我必须从拉取请求中删除除第一个提交之外的所有更改。我该怎么做?
首先,确保您当前的工作树是干净的,然后在最后一次提交时创建一个新分支以确保您不会丢失您的工作:
git stash
git checkout -b unrelated-stuff
现在,您切换回拉取请求分支:
git checkout feature
然后您重置分支以指向特定的提交 ID(您将通过 git log
或通过任何 GUI 应用程序找到该 ID):
git reset --hard COMMIT_ID
一旦您的本地 feature
分支指向您喜欢的提交,您可以将该分支强制推送到服务器:
git push --force
此时,您在服务器上的拉取请求将仅包含相关提交,不相关的工作仍然在 unrelated-stuff
分支上可用。
如果您在 git stash
编辑之前有任何未保存的工作,您可以使用 git stash pop
找回它。
Please note that force-pushing is a highly discouraged operation in git, because it could break other people's local repositories. It should be generally ok in the context of pull requests (many repo owners prefer merging PRs only when they are clean and tidy after reviewing), but never ever force-push into master or other branches where there is potential that other people are working on.
理解和学习 git 的重要资源是 http://learngitbranching.js.org - 如果您有兴趣,请看一看!