Git randomly tracked configuration file

Take, for example, the following scenario:

  • You accidentally track and freeze a configuration file
  • Each development environment must have its own configuration file, so you must have .gitignore before git add
  • You have not understood for a long time that

the end

 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 the cherry disk has returned to C, D or E, it will overwrite the configuration file.

Does C-E need to be rewritten at all by applying the commit B to them?

+7
source share
2 answers

If the configuration file should simply not be verified, it is better to commit over E by tracking the configuration file, adding it to gitignore, etc. If there is confidential information in the config, in this case it should be deleted from any repo commit, you have no other choice but to change the history (this help page from GitHub tells how you can do this - http: // help. github.com/remove-sensitive-data/ )

Due to the nature and requirements of Git, you cannot make changes to a commit and make it the same commit.

+3
source

If authors are all that you and you don’t need to save dates on the errors mentioned (all of them, AE), it will be almost trivially easy, the other way will take longer

Working with your image, I will add revision F as a commit before the error. Assuming you are on the "master" branch,

 git log --oneline master~6..master 

should show you these changes.

 git branch corrected master~5 # this is F, master~0 is A ie the branch tip git config advice.detachedhead false # just to get it to stop blabbing at you # make corrected commit E git checkout master~4 git rm --cached yourconfigfile echo ref: refs/heads/corrected >.git/HEAD git cat-file -p master~4 | sed 1,/^$/d | git commit -m- # make corrected commit D git checkout master~3 git rm --cached yourconfigfile echo ref: refs/heads/corrected >.git/HEAD git cat-file -p master~3 | sed 1,/^$/d | git commit -m- # ... repeat for C, B, and A 

In the end,

 echo ref: refs/heads/master > .git/config 

and you're done. Saving author / date information is a matter of setting GIT_ {AUTHOR, COMMITTER} _ {NAME, EMAIL, DATE} from the git cat-file -p headers git cat-file -p shows you if I need it, I'm preparing sed for you.

0
source

All Articles