从 Git 中的拉取请求中删除包含内容的文件夹
Remove folder including content from a pull request in Git
我提出了拉取请求,现在我必须在合并之前删除 .vscode 文件夹。
如何从我的分支中删除该文件夹,然后再次推送没有该文件夹的版本?
.vscode 文件夹在我的 .gitignore 中,但经常被忽略。我必须手动删除它。
(假设您是功能分支的 "owner",就像在许多工作流程中一样。)
# start from your feature branch
git checkout <feature-branch>
# undo last commit but keep changes in the working tree (and index)
git reset --soft HEAD^
# get your unwanted folder out of the index
git reset HEAD -- path/to/folder
# redo your commit, this time without the folder
git commit -m "Useful message"
# push to the remote to replace the old ref, thus needing --force
git push -f origin HEAD
此时,远程只需要刷新页面(用新的分支引用更新您的拉取请求),您将设置为合并您的分支,这次没有 "bad" 文件夹.
您可以手动删除文件夹,git commit --amend
到您现有的提交,git push -f orign YOUR_BRANCH
仅供参考,确保 .vscode/
在你的 .gitignore 中,结尾 / 是必需的。
我提出了拉取请求,现在我必须在合并之前删除 .vscode 文件夹。
如何从我的分支中删除该文件夹,然后再次推送没有该文件夹的版本?
.vscode 文件夹在我的 .gitignore 中,但经常被忽略。我必须手动删除它。
(假设您是功能分支的 "owner",就像在许多工作流程中一样。)
# start from your feature branch
git checkout <feature-branch>
# undo last commit but keep changes in the working tree (and index)
git reset --soft HEAD^
# get your unwanted folder out of the index
git reset HEAD -- path/to/folder
# redo your commit, this time without the folder
git commit -m "Useful message"
# push to the remote to replace the old ref, thus needing --force
git push -f origin HEAD
此时,远程只需要刷新页面(用新的分支引用更新您的拉取请求),您将设置为合并您的分支,这次没有 "bad" 文件夹.
您可以手动删除文件夹,git commit --amend
到您现有的提交,git push -f orign YOUR_BRANCH
仅供参考,确保 .vscode/
在你的 .gitignore 中,结尾 / 是必需的。