S
S
sorry_i_noob2019-02-15 14:05:53
git
sorry_i_noob, 2019-02-15 14:05:53

How can I remove a folder from the repository starting from the Nth commit using the command (I added the folder, but did not push it)?

Hello. I found this command online:

git filter-branch --force --index-filter "git rm -r --cached --ignore-unmatch BIG/DIR" --prune-empty --tag-name-filter cat -- --all

Instead of BIG / DIR, the name of the folder that needs to be removed from the local repository (after which it can be added to gitignore).
It works well, but how do I specify in it - from which commit this folder appeared? This command looks at ALL commits, which then causes problems if you push.
I added a folder to git that shouldn't be there. Haven't pushed yet. I want to remove it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Anisimov, 2019-02-15
@Blacknife

In order not to execute commands that are incomprehensible to you, just remember a simple sequence in this case:
1. accidentally added something to git, committed
2. to remove random files from the repository, you just need to delete these files (transfer temporarily somewhere from the repository) and immediately commit the changes
3. add the file/folder to gitignore, commit
4. return the old location to the file/folder, it will not be included in the commit anymore. In
total, you should get 2 commits for fixing, the first one deletes the files, the second one adds them to gitignor. If at the first point you have already pushed the changes to the remote repository, then after step 3 push again and that's it.
Perhaps you accidentally committed a file containing a password and now want to make your project public, for example, to remove the passwords.txt file from your entire history, you can use the --tree-filter option of the filter-branch command:
https://git-scm.com/book/ru/v2/%D0%98%D0%BD%D1%81%...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question