Update commits to consider changes in . gitignore

Asked

Viewed 145 times

0

I have the following situation:

I created a repository git from a remote of the Github.

I did several commits in the local repository (without push to the remote).

When I went to perform push for the remote, it was rejected because it has files larger than 50MB.

So I changed the .gitignore to ignore files larger than 50MB (I don’t need them in the remote repository).

I made a new commit with the change in .gitignore.

Even so, the rejection of large files still occurs (>50MB).

I found some answers that talk about reset but I’m afraid to do it, because I can’t lose the job already done.

How do I "update" the commits to consider the amendment of .gitignore which deletes the large files and send the push to the repository?

2 answers

2

After a few more hours of research, I found the solution in Removing sensitive data from a Repository

git filter-branch --force --index-filter "git rm --cached --ignore-unmatch PATH-TO-YOUR-FILE-WITH-SENSITIVE-DATA" --prune-empty --tag-name-filter cat -- --all

where PATH-TO-YOUR-FILE-WITH-SENSITIVE-DATA is the way for files to delete from commits.

After actualziar the .gitignore, just make a new commit and run:

git push origin --force --all.

1

git rm --cached <arquivo> removes the archive from the repository (git then stops trackear of that file), but it remains in its workspace. It is very common to use this command after adding a file to .gitignore and you want to remove it from the repository once it has been committed. It is the most used and very safe approach.

It’s important to remember to use the --cached, for only git rm removes the file completely. I also suggest to read the file itself documentation.

  • 1

    Thank you @Igor Cavalcanti, but I had already tried this solution and it didn’t work. Anyway, last night I spent some more time researching the Github documentation and found something that worked.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.