A simple tool for storing and restoring complete files metadata (mode, owner, group) in a git repository. It’s designed especially for versioning /etc.
Metadata is tracked using the .metafile
file, which is automatically updated and added to commits.
This file is in TSV (tab-separated values) format to be easily readable and diffable.
#%GIT-METAFILE 1
# <path> <mode> <uid> <gid>
.gitignore 100644 0 0
.metafile 100644 0 0
profile.d 40755 0 0
shadow 100640 0 42
If you’re using Alpine Linux, you can install git-metafile package from the Alpine’s community repository:
apk add git-metafile
If you’re using Arch Linux, you can install git-metafile package from AUR:
yay -S git-metafile
Or use another AUR helper.
If you’re a Rust developer, you can build and install git-metafile from crates.io using cargo
:
cargo install git-metafile
Note that the binary may be bigger than expected because it contains debug symbols.
To remove debug symbols and therefore reduce the file size, run strip
on the binary.
If your package manager doesn’t provide git-metafile, you can use a pre-built binary.
On Linux, you can choose either a statically linked [1] (static) binary that should work on every Linux system (distro), or, if you’re using a sufficient recent GNU/libc-based (glibc) distro (most major distros), a dynamically linked binary.
-
Install git (use your system’s package manager).
-
Download and extract release tarball for your OS and CPU architecture (pick the right link from the list above):
curl -sSLO https://github.com/jirutka/git-metafile/releases/download/v0.2.3/git-metafile-0.2.3-x86_64-linux.tar.gz curl -sSL https://github.com/jirutka/git-metafile/releases/download/v0.2.3/checksums.txt | sha256sum -c --ignore-missing tar -xzf git-metafile-0.2.3-*.tar.gz
-
Install
git-metafile
somewhere on yourPATH
, e.g./usr/local/bin
:install -m 755 git-metafile-0.2.3-*/git-metafile /usr/local/bin/
-
Install git (use your system’s package manager).
-
Download and unpack the tarball:
wget https://github.com/jirutka/git-metafile/archive/v0.2.3/git-metafile-0.2.3.tar.gz tar -xzf git-metafile-0.2.3.tar.gz cd git-metafile-0.2.3
-
Build git-metafile using cargo:
cargo build --release --locked
-
Grab the binary from
target/release/git-metafile
and install it somewhere on yourPATH
, e.g./usr/local/bin
:install -D -m755 target/release/git-metafile -t /usr/local/bin/
To automatically record files attributes on every commit and restore them on every checkout, set up git hooks:
cat >> .git/hooks/pre-commit <<EOF
#!/bin/sh
git-metafile save && git add .metafile
EOF
chmod +x .git/hooks/pre-commit
cat >> .git/hooks/post-checkout <<EOF
#!/bin/sh
git-metafile apply
EOF
chmod +x .git/hooks/post-checkout
ln -s post-checkout .git/hooks/post-rewrite
This should work for all basic operations, so you don’t need to think about it anymore. However, you have to be careful when rebasing – no hook is run when git checkouts files during rebase and before committing changes done in rebase mode!
To record changes or restore files attributes manually, you can run git metafile save
or git metafile apply
respectively.
This project is licensed under MIT License. For the full text of the license, see the LICENSE file.