git accidentally tracked config file

git, version-control

Solution

If the config file should just be untracked, better make a commit over E untracking the config file, adding it to gitignore etc. If the config has sensitive information, in which case it must be removed from any commit of the repo, you have no other go but modifying history ( This help page from GitHub talks about how you can do this - http://help.github.com/remove-sensitive-data/ )

Due to the very nature and requirements of Git, you cannot make a change to a commit and make it seem to be the same commit.

Problem

Take for example the following scenario: - You accidentally track and commit a config file - Each development environment should have their own specific config file, so you should have `.gitignore` before `git add` - You didn't realise for quite a while The commits ``` A - B - C - D - E | | | | | \ | / | commits that accidentally track application config | commit to untrack & .gitignore config [finally you did the right thing... but too late?] ``` If you ever reset or cherry-pick back to C, D, or E, it'll overwrite the config file. Is there anyway to rewrite C - E by applying the B commit on them?

Original source