I am using the work flow introduced by Successful Git branch. I am confused about how to manage changes,like configuration in develop branch.
When I merge from master, to keep working tree clean I stash the changes. If I commit the changes, I should be very careful when I merge back master.
So is there a better way to manage private changes in git?
If you have committed changes to a file (i.e. you have run both git add and git commit ), and want to undo those changes, then you can use git reset HEAD~ to undo your commit.
Git Checkout FileIf you stage and commit the checked-out file, this has the effect of “reverting” to the old version of that file. Note that this removes all of the subsequent changes to the file, whereas the git revert command undoes only the changes introduced by the specified commit.
The reason for error messages like these is rather simple: you have local changes that would be overwritten by the incoming new changes that a "git pull" would bring in. For obvious safety reasons, Git will never simply overwrite your changes.
There are several options:
Do not put private files under source control. For instance, if you need a config.ini
with private changes for each developer, then create a file config.ini.template
with example settings in the repository, then each developer should make a copy of it and amend the copy with private settings. The config.ini
should be added in the .gitignore
.
Add the config.ini
in the repo and use git update-index --assume-unchanged config.ini
so that git will ignore any local changes in the file not try to commit the file.
Add several config files in the repo for each environment, e.g. config-robotment.ini
, config-kan.ini
, config-produciton.ini
and so on. Then use a command line parameter, or an environment variable, or something similar to allow your application choose which file to use.
And the point is - don't use branches for the configuration, otherwise it will be always painful to branch/merge during development.
For configuration file, the choices are resumed in "Git: keep specific files unmerged".
I prefer versioning different value files for each environment (here for each branch), that way I don't have to deal with merge (the value file "dev.config
" would never be modified in master branch, where the value file "master.config
" is used)
I also version a template file, in order for a content filter driver to generate the actual config file (which remains private and isn't version) on checkout of the branch:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With