GIT: Remove files from commit


Posted:   |  More posts about git

There are lot of ways if you search for this, mostly involve in ammending the commit. But if you only accidentally added the files in a development/temporary branch, there's much simpler way than meddling around with the history.

When you merge branch, git will automatically commit all the changes from that branch. But there's a way to stop that.

$ git checkout -b new-layout-fixout
$ git merge new-layout --no-commit --no-ff
Automatic merge went well; stopped before committing as requested
$ git status
# On branch new-layout-fixout
# Changes to be committed:
#
#       modified:   harga/models.py
#       modified:   harga/search_indexes.py
#       modified:   harga/templates/base.html
#       new file:   harga/templates/sidebar.html
#       new file:   scrapers/scrapers.db

Let say scrapers/scrapers.db is the file that we accidentally committed and we don't want it. Just remove it from the index:-

git reset HEAD scrapers/scrapers.db

Now the file has been removed, we can commit the rest of the changes.

Comments powered by Disqus

About me

Web developer in Malaysia. Currently work at MARIMORE Inc building internet services using Python and Django web framework.

ImportError is an error message emitted by Python when it failed to load certain module as requested by programmer. It's a very common error when someone new to the language trying it out. This website on the same theme, will try provide help for newcomers on any technologies to overcome their first hurdle.

Try most of the examples you may find here on Digital Ocean cloud service. They provide excellent VPS at a very cheaper price. Using this referral link you'll get USD10 credits upon sign up. That's enough to run single VPS with 1GB RAM for a month.

Others

I can also be found at the following sites:-

  • http://k4ml.blogspot.com/
  • http://k4ml.github.io/
  • http://metak4ml.blogspot.com/
  • http://www.mydev.my/
  • http://github.com/k4ml/

Disclaimers

The postings on this site are my own and don't necessarily represent my employer's positions, strategies or opinions.

Share