5

I am experimenting some linux configuration and I want to track my changes? Of course I don't want to to put my whole OS under version control?

Is there a way (with git, mercurial or any VCS) to track the change without storing the whole OS?

This is what I imagine:

  1. I do a kind of git init -> all hashes of all files are stored, but not the content of the files
  2. I make some changes to my file system -> git detect that the hash of this file has changed
  3. I commit -> the content of the file is stored (or even better the original file and the diff are stored! I know, that is impossible... )

Possible? Impossible? Work-arounds?

EDIT: What I care about is just to minimize the size of the repository and to have a repository containing only my changes. Having all files in my repository is not relevant for me. For example if i push to github I just want it to contain only the files that has changed.

1
  • If all you care about is being notified when something changes, how anout Tripwire?
    – tripleee
    May 26, 2012 at 7:25

4 Answers 4

4

Take a look at etckeeper, it will probably do the job.

2
  • Correct me if I am wrong but this tool seems to be only a hook on apt that trigger a commit. That's definitely useful but not really related to my question. All files content are stored in the repository.
    – tibo
    May 26, 2012 at 4:18
  • From website and README: "It hooks into apt (and other package managers including yum and pacman-g2)", "You can also run etckeeper commit by hand to commit changes.", "There is also a cron job, that will use etckeeper to automatically commit any changes to /etc each day."
    – cirne100
    May 26, 2012 at 4:24
1

What you want is git update-index --info-only or ... --index-info, from the man page: " --info-only is used to register files without placing them in the object database. This is useful for status-only repositories.". --index-info is its industrial-scale cousin.

Do that with the files you want to track, write-tree to write the index structure into the object db, commit-tree that, and update-ref to update a branch.

To get the object name use git hash-objectfilename.

1
  • Awesome! Exactly what I was looking. Git is definitely awesome when you know how to use it! How can you do to add all files of the OS?
    – tibo
    May 26, 2012 at 9:35
0

Here is what we do...

su -
cd /etc
echo "*.cache" > .gitignore
git init
chmod 700 .git
cd /etc; git add . && git add -u && git commit -m "Daily Commit"

Then setup crontab:

su -
crontab -e

# Put the following in:
0 3 * * *   cd /etc; git add . && git add -u && git commit -m "Daily Commit"

Now you will have a nightly commit of all changes in /etc

If you want to track more than /etc in one repo, then you could simply do it at the root of your filesystem, except add the proper ignore paths to your /.gitignore. I am unclear on the effects of having git within git, so you might want to be extra careful in that case.

1
  • That would be too simple ;) I know how to track changes with git. If I rephrase my question : How to track the changes without keeping in the repository all files that have not change? My issue is that I track a lot of things (/etc, /usr, /home ...) and it takes a lot of memory while most of the files won't change (but I want to be notified if any file change...).
    – tibo
    May 26, 2012 at 4:11
0

I know this question is old, but I thought this might help someone. Inspired by @Jonathon's comment on the How to record concrete modification of specific files question, I have created a shell script that enables you to monitors all the changes done on a specific file, while keeping all the changes history. the script depends on the inotifywait and git packages being installed.

You can find the script here https://github.com/hisham-hassan/linux-file-monitor

Usage: file-monitor.sh [-f|--file] <absolute-file-path> [-m|--monitor|-h|--history]  
       file-monitor.sh --help  

 -f,--file <absolute-file-path> Adding a file to the monitored files List. The <absolute-file-path>  
                                is the absolute file path of the file we need to action.  
                                PLEASE NOTE: Relative file path could cause issues in the script,  
                                please make sure to use the abolute path of the file. also try to   
                                avoid sym links, as it has not been tested.  
                                example: file-monitor.sh -f /absolute/path/to/file/test.txt -m  
 -m, --monitor                  Monitoring all the changes on the file. the monitoring will keep  
                                happening as long as the script is running; you may need to run it  
                                in the background.  
                                example: file-monitor.sh -f /absolute/path/to/file/test.txt -m  
 -h, --history                  showing the full history of the file.  
                                To exit, press "q"  
                                example: file-monitor.sh -f /absolute/path/to/file/test.txt -h  
 --uninstall                    uninstalls the script from the bin direcotry,  
                                and removes the monitoring history.  
 --install                      Adds the script to the bin directory, and creates  
                                the directories and files needed for monitoring.  
 --help                         Prints this help message.  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.