我想在Git提交中删除因错误而添加的文件。
我尝试了这段代码,但惊讶地发现它会永久删除该文件。请问有谁可以帮助我?
请问有谁可以帮助我吗?我所有的测试都失败了。
我是按照这个链接(从Git提交中删除文件)中的说明进行操作的:
git reset --soft HEAD^
git reset --soft HEAD~1
git reset HEAD path/to/unwanted_file
git commit -m 'remove unwanted file'
我想在Git提交中删除因错误而添加的文件。
我尝试了这段代码,但惊讶地发现它会永久删除该文件。请问有谁可以帮助我?
请问有谁可以帮助我吗?我所有的测试都失败了。
我是按照这个链接(从Git提交中删除文件)中的说明进行操作的:
git reset --soft HEAD^
git reset --soft HEAD~1
git reset HEAD path/to/unwanted_file
git commit -m 'remove unwanted file'
git checkout revision-where-it-was-added
git rm --cached the-file
git commit --amend --no-edit
git cherry-pick HEAD@{1}..the-branch # replay the other revisions in the branch
# if you like this resulting history:
git branch -f the-branch
git stash save "Will come back in a few minutes"
。然后,当你完成整个操作时:git stash pop
。 - eftshift0