I am trying to do something unusual (?) with Git --- storing my multimedia files and photos and some pdf files with Git. I want to keep some meta data with each file (e.g., with a photo: I w开发者_运维百科ant to keep some sort of caption with it; with a pdf file: some information about what the file is about for ease of searching later on). In svn you can use svn properties to store metadata about a file (I think). How do I do the same in Git? Haven't been able to find any easy way! git notes
looked promising, but it only associates notes with objects (commits). I want notes with individual files.
Update: I do not want to keep a separate file for metadata of files/paths! :-) I want to keep the information with the file/path somehow. Like svn properties (svn propset caption "In the Golden Gate" foo.jpg
). To be more precise, when I move files around (git mv path1/file path2/file
), I don't want to have to worry about keeping the metadata file up to date... the metadata should move with the file.
Just keep in separate files, and do a pre-commit
hook to fix them.
You can detect renamed file (in index/cache) using git diff --cached -M --summary
[flames]$ git diff --cached -M --summary
rename a => b (100%)
then do fancy stuffs (i suggest using perl, but I use sed here just for demo)
[flames]$ git diff --cached -M --summary | \
> grep rename | \
> sed 's/^ rename \(.*\) => \(.*\) (.*/s\/^\1$\/\2\//'
s/^a$/b/
use this regex on your note file (not tested):
#!/bin/sh
REGEX="`git diff --cached -M --summary | \
grep rename | \
sed 's/^ rename \(.*\) => \(.*\) (.*/s\/^\1$\/\2\//'
`"
sed -i -e "$REGEX" note-file
git add note-file
exit 0
A easier to parse format is the --raw
format.
[flames]$ git diff --cached -M --raw
:100644 100644 b53a58b... 3f063ab... M wxyz
:100644 100644 e69de29... e69de29... R100 a b
Just search for R on the 5th column. man diffcore(7) for details. This is leave as an exercise for reader.
It sounds like you'd need a solution outside of Git that can handle editing metadata of various filetypes. Either that or you can create a text file for every single piece of media you want metadata for, but that sounds impractical.
Have a look at gibak: https://github.com/mfp/gibak
精彩评论