开发者

Rolling back a git tree, fully or partially (single file) how to?

开发者 https://www.devze.com 2023-02-02 05:53 出处:网络
On a given server, I have a set of daemons each of which has its own configuration file. I would like to use git to manage the configuration files editing during time and always have the option to ro

On a given server, I have a set of daemons each of which has its own configuration file.

I would like to use git to manage the configuration files editing during time and always have the option to rollback to the "factory defaults" in regards to all files or a specific one.

For instance, given the following structure:

$ ls -l
total 0
-rw-r--r-- 1 tzury tzury 0 2011-01-05 06:36 bar.conf
-rw-r--r-- 1 tzury tzury 0 2011-01-05 06:36 baz.conf
-rw-r--r-- 1 tzury tzury开发者_运维技巧 0 2011-01-05 06:36 foo.conf

Assuming all those .conf files are stored in a git repository, I want to be able to restore all files into their original shape (that would be the first git commit). Yet, I would also like to be able to rollback a specific file to the factory defaults, while others remain up to date.


To get a single file from an earlier commit just checkout that file from there.

git checkout FACTORY_DEFAULT_COMMIT -- foobar.conf


Usually what I've done is have prototype config files stored in Git, but not used by any programs. Once you checkout the prototypes, you then copy them and the copies become the actual config files, which can be edited and customized for the particular checkout. Any changes that should be kept will also be made to the prototypes and committed accordingly. The copies are in .gitignore and will never be version controlled.

In Git, you'd have files foo.conf.in, bar.conf.in and baz.conf.in. Once you check these out, you make copies to foo.conf, bar.conf and baz.conf. These files are explicitly ignored in .gitignore (or you can ignore all .conf files if all of them operate in the same fashion). If you want to update the "factory defaults", you'd make changes to foo.conf.in, etc. and then commit them. Otherwise, rolling back is a simple matter of recopying the .conf.in files over the .conf files.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号