Once again, having lost a valuable config because of the confused Shell> and >>, I finally realized
it's time to make backups.

You can make copies of configs somewhere in a secluded place on the disk, you can make rsync to a remote server
or write sly bicycle scripts.
But the most convenient solution is already right at hand: create a git repository at the root.
If someone else does not know, git does not force us to raise any server. In general, the repository in git is first of all a local entity, and even more so, the repository is the only one .git directory. As for the possibilities of interaction with external repositories, no one obliges them to use.
')
And now the technical details.
Common sense or prevention of shooting limbs
Item number one: Filtering entries by paths and keeping all / etc in the repository is an inconvenient approach.
Firstly, / etc is full of default garbage (since tz values for us to these configs),
secondly, for example, I want to keep / var / lib / portage / world as close to my heart as some of the files in / etc.
Point number two: If you ever want to put your configs repository on a githab,
your / etc / ssh / ssh_host_rsakey may attract
unexpectedly a lot of attention from local users.
Based on this, we define the contents of the .gitignore file (indicates files that will not automatically be offered for addition, as well as exceptions to these rules)
/.gitignore (forbid everything):
*
Yes, nothing more. The bottom line is that git has already added (in some way contrary to .gitignore) files as usual, and new ones will not be automatically offered to be added.
Total, it is enough to add config once
add -f path-to-config/config
henceforth, it can be committed via commit -a or add -A.
A little bit about git
Nothing new for those who already use gitFiles in our repository can be in three categories:
not in index (untracked) - [new] files that we sifted through .gitignore
unstaged - changed / new files that are not yet selected for commit.
staged - respectively, selected for a commit via add.
You can see the list of changed files in
# git status
or to view all monitored files
# git ls-files
Illustration (with the only remark that stage is a synonym for add and, accordingly, a new file can be immediately committed without “edit the file”)
Recipes:
Nothing new for those who already use gitCreate repository:
localhost / # git init
Add config:
# git add path-to-config/config -f
(-f key will be needed only for new files)
See what's new:
# git status
What specifically new:
# git diff
Select all modified files for commit:
# git add -A
Commit:
# git commit [-m "message"]
(if without -m, the editor will open to describe the commit)
The combination of the two previous commands:
# git commit -a [-m ...]
Story:
# git log [--stat]
(shows including hashes (object name) of commits that can be used in other commands. In this regard, the option --abbrev-commit is useful)
What has changed between two commits:
# git diff COMMIT COMMIT
(you can use HEAD ~ N to indicate a commit that is remote from the newest to N or just HEAD)
Rollback last commit:
# git reset --hard HEAD~1
or return to commit:
# git reset --hard COMMIT
Rollback, rewrite history
Single file recovery
Expulsion of shower deleted files
Branches and other
$ man git
$ links
http://git-scm.com Total
I have a git watching the following files:
/ etc / bash / bashrc
/etc/make.conf
/etc/portage/env/splitdebug.conf
/etc/portage/package.accept_keywords
/etc/portage/package.unmask
/etc/portage/package.use
/ etc / sudoers
/ var / lib / portage / world