I wanted to remove a file from my very first initial commit:
git rebase -i --root
set the first commit to edit
git rm *filename
git commit --amend
git rebase --continue
Now I have a new commit that consists of the history of commits (which successfully removed the file I wanted from initial commit), but previous commits also remain. So there are duplicate commits now. My question is how to only want to keep my most current commit.
Looks like something is still referencing them. It may be because you have other branches, which are still pointing to some of the old commits .Run git log --all --graph
to see what it is.
You can then reset your branches to their new, rebased commits by doing git checkout <other_branch>
, then git reset --hard <new_rebased_commit>
.
Once you're done, you may want to delete the old commits by running git gc --prune=all
. If you don't do that, they can still be found, for example, by using git reflog
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.