Get all file changes in git

I have a git repository with several files in it.

I need to get all the changes (not demarcation) of a particular foo.bar file and save it as something like 0001-{date}-{sha}-foo.bar , 0002-{date}-{sha}-foo.bar , etc. d. in the new folder.

How can i do this?

+4
source share
2 answers

Assuming you want the author date, and that the unix timestamp is fine:

  i = 0
 git log --reverse --format =% H \% at $ file |
 while read hash date;  do
   git show $ hash: $ file> $ (dirname $ file) / $ i- $ hash- $ date - $ (basename $ file)
   : $ ((i + = 1))
 done

should do what you want. Change the% at specifier parameter if you want different dates, but the unix timestamp is good, since you do not need to deal with spaces in the name. Obviously, there are ways to handle this if you choose.

+6
source

You can use git log --pretty="%ct %H" -- foo.bar , which will give you something like:

 1322212187 f75e724eec4e11a720d4620b3ca09eff91bb754e 1311666567 d6b578f1b778c67d78322d914d3ab46e02d12f6c 1311584563 cb76c3e39553cf20c9e96ad3d2c963b905d19180 1311321178 bec391005805ca01e9c7b11032b456d426f4fa52 1311321089 b29afbf8c4ca7e8f178cec981b5d3d14f0abeb15 1311081641 74d5747f2094a8f1696344c6c2b94244e52c7cc9 

The first column is the commit label (unix), the second is the SHA commit. You can change the date format if you want something else (' %ct ' in the argument --pretty , RTFM to view the options) if you want. From this, it would be easy to write git commands to test this particular revision of this particular file and copy it using the naming convention with shellscript - on the left as an exercise for the reader.

+4
source

Source: https://habr.com/ru/post/1383061/


All Articles