Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git remove files from very first commit

Tags:

git

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.

like image 991
A. L Avatar asked Oct 24 '17 06:10

A. L


People also ask

Can you remove files from a commit?

You can remove the file from the latest commit with git rm .

How do I remove top commit most?

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.

How do I remove a large file from a git commit?

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.


1 Answers

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

like image 70
Dave Wood Avatar answered Sep 28 '22 07:09

Dave Wood