1

I have made some changes on the .git/hooks directory. Now I wish to abandon those changes and restore .git/hooks to its initial status. Can I do this and how?

Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
Pan Ruochen
  • 1,990
  • 6
  • 23
  • 34

3 Answers3

1

The Git directory .git is not versioned. Git does not save copies of files in the .git/hooks directory. You have to make backups yourself.

Dietrich Epp
  • 205,541
  • 37
  • 345
  • 415
  • When I clone the remote repository to local, there exist the hook directory inside .git. So I wonder if there is some way to synchronize hook again with the remote. – Pan Ruochen Dec 12 '12 at 09:38
  • 1
    @PRC The initial contents of the hook directory come from the local system, not from the repository being cloned. The same initial hooks would be present in a new repository created with `git init`. – qqx Dec 12 '12 at 15:12
1

Git only tracks what is in the working directory and omits the .git folder.

However, you can track whatever you like in the git folder by making a separate branch, then telling git that the worktree exists there. I showed how to do this with rerere and the rr-cache that it creates. Sample syntax is:

git --work-tree=.git/hooks --git-dir=.git add -A

You'll have to repeat those options for the commit as well.

Here is the post on how to share your rerere cache: Sharing rerere cache

That should get you started if you want to share your hooks.

Community
  • 1
  • 1
Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
0

The simplest way to get the initial hooks back is likely to just remove the current hooks, create a temporary repository with git init, and copy the hook scripts from there into your existing repository's hooks directory.

You could also try to find where git stores its default hook templates on your system, and copy them directly from there.

qqx
  • 18,947
  • 4
  • 64
  • 68