I
I
iPathfinder2020-05-18 06:34:18
git
iPathfinder, 2020-05-18 06:34:18

How to remove a file from commit history in GIT?

Just learning how to use GIT.
There is a project - one branch with a history of 10 commits , on Github launched from the 1st to the 4th . Since I work with the project alone and currently from one computer, I committed the changes for a while, but did not push. So HEAD points to the 10th commit.

I tried to push to the server, but I got an error - github told me that it found large files (more than 100mb) and they cannot be uploaded. Ok, indeed, my log file, which was in the monitored folder, has grown. I deleted the file in PyCharm via safe-delete, committed it, tried to push - again an error.
I googled it, realized that I had deleted it wrong and deleted it again via git rm <file_name>. Commit, push does not pass - again an error. I look at the history and understand that the file has grown on the 6th commit . And as far as I understand, the push does not go through precisely because of the large file in the 6th commit (although it is strange that the 5th commit did not push either).
I don't need this file, I want to get on the server from the 1st to the 10th commit. How can I do that?

PS I found information about BFG Repo-Cleaner on help.github, but I understand that it is used in similar situations when changes have already been pushed to the server, but in my case I don’t understand whether it can be used. I'm afraid to break something (after this error, for some reason, Pycharm began to crash for me). I saved the latest version locally, but I would like not to lose the history of changes from 5 to 10 commits.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
iPathfinder, 2020-05-19
@iPathfinder

Used BFG Repo-Cleaner at my own risk, it helped in my case.
If someone has a problem, like me, I tell you what I did, because did not quite according to the instructions , i.e. without creating a "bare repo".
I launched Repo-Cleaner with the necessary keys directly in the project folder, after processing I received rebuilt commits with new hashes. I couldn’t push further, because the first 4 commits in the local repository and in the remote did not match. It was necessary either to make a pool and merge, or, as I did, I unlinked origin in the local repository and linked a new one (previously created on github). Then push and I got a new project on github with the whole history of commits.

A
Arseny, 2020-05-18
Matytsyn @ArsenyMatytsyn

git rm --cached [filename]
By the way, if not a lot of work has been done (you don’t have to sit around transferring the code for a day), then you can compare the commits through diff, fish out the difference (in some kind of file) and calmly roll back to the old one, and then recover if something goes wrong not this way.

D
Dmitry, 2020-06-01
@dlnsk

BFG Repo-Cleaner, as far as I understand, is for situations where a cant is 1000 commits ago and all this has already been pushed somewhere. You have only 10 commits and seem to want to learn something.
1. If something is committed - it is impossible to spoil (there is always an opportunity to restore).
2. Apparently you are working in the master branch. Create a test branch on the last commit and do whatever you want with the master - test will remain unchanged (you can always move master back to test and start over).
3. git rebase --interactive <commit 5> (then mark the commits you want to edit and either delete the file altogether or eliminate the increase).
Other ways to get rid of the file: https://itextpdf.com/en/blog/technical-notes/how-c...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question