It is necessary to teach git v1.9.5 to commit certain files from one directory to another before committing and after that to commit.

since the commit gets files after git add and the git add not thought up, it turns out that after my utility is called from the pre-commit hook and does everything that is necessary, the files generated by it do not get into the commit.

win xp (x86)

Is there a solution?

  • use git mv <file> ? But just do not understand why such perversion is needed. - KoVadim 1:53
  • @KoVadim perversion is needed in order to be able to use git for ert-files 1c 7.7 which must be transported using gcomp - Vyacheslav Danshin
  • @KoVadim can say more about how I can use mv to add files to a commit? If I understand correctly, this command simply transfers files from one directory to another - Vyacheslav Danshin
  • I misread the question. In the pre-commit hook, did you try git add for new files? but in general something like this is not done. And if you need new files, apply deploy scripts. - KoVadim 1:59
  • @KoVadim in the pre-commit hook I call exe-shnik which does some magic after which ert-files are broken into a set of files. Then in the same hook I write git add . but files are not added to the commit. - Vyacheslav Danshin

1 answer 1

An example of a .git/hooks/pre-commit file that simply copies new / modified (others can be - see man git-diff for values ​​for the --diff-filter option) files from the dir1 directory to the dir2 directory (and adds them "Inside" commit):

 #!/bin/sh from=dir1 to=dir2 mkdir -p $to for f in $(git diff --cached --name-only --diff-filter=AM | grep "^$from/"); do n=$(echo $f | sed "s.^$from.$to.") cp $f $n git add $n done exit 0 

instead of copying, of course, you can produce more useful actions.


about the method of selecting files peeped in this answer: Git pre-commit hook: changed / added files

  • Are you sure that git add $n will work for the version of git specified in the question? - Vyacheslav Danshin 2:51
  • This version is not at hand. I use version 1.7.10.4, now I checked on version 2.1.4. in both cases, the result is the same: it works as expected. Test it yourself on a new repository / another machine. - aleksandr barakin 2:55
  • OS win xp 32, and this script does not work - Vyacheslav Danshin
  • win - and then it is clear. I can only sympathize with your difficulties .. - aleksandr barakin
  • The line with for does not work specifically (when adding a new file to the dir1 diff directory, it apparently does not see this and the body of the loop does not work). If replaced by for f in $from; do for f in $from; do then the string n=$(echo $f | sed "s.^$from.$to.") falls by mistake. - Vyacheslav Danshin