So this question isn't this one: Remove files from Git commit although it's similar.
I'm in a situation where I cannot do:
git reset --soft HEAD~1
because I am at the very first commit.
I'm wondering how I would go about removing files from my commit since I cannot backtrack.
You can remove the file from the latest commit with git rm .
To remove the last commit from git, you can simply run git reset --hard HEAD^ If you are removing multiple commits from the top, you can run git reset --hard HEAD~2 to remove the last two commits.
Using git filter-branch This is the most commonly used method, and it helps us rewrite the history of committed branches. Here, the rm option removes the file from the tree. Additionally, the -f option prevents the command from failing if the file is absent from other committed directories in our project.
If it's the most recent commit, you can easily amend it. Just make the changes you want, (delete the file for example), then type:
git commit --amend
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With