Git-已提交和推送的更改中的文件需要取消提交

时间:2018-10-11 14:55:21

标签: git github

在一个单独的分支上,作为拉取请求,我已经提交并推送了一些系统和项目环境文件。它们给其他开发人员带来了巨大的问题,因为它们是我的系统文件,干扰了他们的系统文件。如何从PR中删除这些文件?

1 个答案:

答案 0 :(得分:0)

假设您在my-branch〜3上修改了文件:

git checkout my-branch~3
git checkout HEAD~1 -- some-file.txt some-file2.txt
git commit --amend --no-edit # amend revision, those files will be as they were on previous revision
git cherry-pick my-branch~3..my-branch # rewrite remaining history of branch
# check the branch to make sure everything is of
# if it is... continue with the recipe
git branch -f my-branch #move branch pointer to new rewritten branch
git checkout my-branch
git push --force origin my-branch # adjust name of branch and remote