Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to maintain private changes in git?

Tags:

git

project

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?

like image 872
robotment Avatar asked Sep 06 '12 01:09

robotment


People also ask

How to undo local git changes?

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.

Can I revert git checkout?

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.

Does git checkout overwrite local changes?

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.


2 Answers

There are several options:

  1. 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.

  2. 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.

  3. 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.

like image 122
kan Avatar answered Nov 01 '22 11:11

kan


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:

smudge clean filter driver

like image 37
VonC Avatar answered Nov 01 '22 13:11

VonC