我有一个已经推送到远程分支但尚未合并到主分支的本地分支,并且已经为此更改创建了一个 pull request。在这个提交中有一些不必要的文件。我想知道以下操作是否可行:
- 保存/搁置我想要推送的本地分支中的文件
- 删除本地分支和远程分支
- 从主分支创建一个新的本地分支,将我想提交的修改后的文件移回去,进行提交并推送到远程。
- 创建一个新的 pull request
非常感谢您的帮助和协助。
我有一个已经推送到远程分支但尚未合并到主分支的本地分支,并且已经为此更改创建了一个 pull request。在这个提交中有一些不必要的文件。我想知道以下操作是否可行:
非常感谢您的帮助和协助。
# undo the last commit whilst keeping the changes in the working tree (and staged files)
git reset --soft HEAD^
# remove the unwanted files from the to-be-committed list (the index)
git reset HEAD -- path/to/file1 path/to/file2
# as an alternative if you don't want to keep the changes in these files,
# use --hard here above, but before the --)
# redo the commit
git commit -m "your message here"
2) 使用强制推送将其推送到远程(因为远程已经有旧版本的提交,但我们在历史记录中将其删除了)
最初的回答:Push it to the remote with force.
git push --force origin HEAD
# or alternatively, since your branch is named br/bugfix1
git push --force origin br/bugfix1
3) 更新PR
只需进入您的PR网页并刷新即可。
br/bugfix1
,只有它会被推送,没有其他的。你也可以选择 git push origin br/bugfix1
。 - Romain Valeri--force
的必要性,所以最终是:git push --force origin br/bugfix1
。我们永远不会向 git 投降!(大部分感谢 torek) - Romain Valeri