A
A
Alex_872017-05-29 21:35:51
git
Alex_87, 2017-05-29 21:35:51

Removing commited files in git?

Hello! Please tell me how to remove the committed (git add) changes and return to the previous ones. I'll explain the situation... I just committed the changes with the command (git add . ) This allows you to not only commit changes to files, but also adds new ones. So, by accident I added a folder with files (node_modules)
So I want to remove this commit and revert back to the previous one. And one more thing ... Is it possible to somehow put the folder in git ignore in order to avoid accidental addition in the future. Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene Wolf, 2017-05-29
@Wolfnsex

Is there any way to put the folder in git ignore to avoid accidental adding in the future. Thank you!
You can, create a .gitignore file in the root and write something like the following there (my .gitignore file):
.idea/
nbproject/
node_modules/
css/

Removing files "accidentally" in the history, from this very history, incl. if you have already made a commit (and even if not one) is done using the git-filter-branch command (there are examples on the link). Including about this, you can read here or even find it on the "Toaster" itself, for example here .
PS And in this regard, sometimes an IDE called "PHPStrorm" helps a lot, showing hints like "Ignored files are present in the repository history" and even prompting commands on how to remove these files from the repository history :)

B
Bogdan, 2017-05-29
@bogdan_uman

One file git rm .idea/workspace.xml --cached
Whole foldergit rm -r .idea --cached

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question