0

In my workflow I want to make some changes in file and keep them in my local machine. For this purpose I have written a pre-commit hook to reset those files before any commit.

The problem is that the default message:

# Changes to be committed:
#   FileToBeCommited1
#   FileToBeCommited1
#   FileAlreadyResetByPre-comitHook

has a list of files that will be committed. Fore some reason it always contain the names of the files that I have already reset in my hooks. Its not really a big problem, but I would like it to be resolved if possible. Also I don't want to write prepare-commit-msg hook to write the full message myself.

Suryavanshi
  • 595
  • 1
  • 7
  • 24

1 Answers1

0

Another approach would be to ignore local changes for those files using git update-index:

git update-index --skip-worktree -- file1
git update-index --skip-worktree -- file2
git update-index --skip-worktree -- file3

That way, no need for a hook resetting those.
And the commit message remains clean.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • thanks, but am not looking for alternative, cause this method has its own down sides, like rebase or merge overwrites silently. In pre-hook method I have to consciously stage and re-apply... I like that approach better – Suryavanshi Mar 29 '16 at 07:08
  • @Suryavanshi to my knownledge, those skipped files are *not* overwritten silently (as in http://stackoverflow.com/q/27027732/6309) – VonC Mar 29 '16 at 07:13
  • In my personal experience, they did get overwritten during `git pull --rebase` – Suryavanshi Mar 29 '16 at 07:38
  • @Suryavanshi What git version are you using? – VonC Mar 29 '16 at 07:39
  • @Suryavanshi Could you test it with git 2.7.4 or git 2.8? – VonC Mar 29 '16 at 07:42
  • Will update, if I get to it. Currently 1.9.1 is the latest in ubuntu repo – Suryavanshi Mar 29 '16 at 07:43
  • @Suryavanshi I have documented how to upgrade before: http://stackoverflow.com/a/34469473/6309. git 2.8 is available in that ppa since... an hour ago ;) – VonC Mar 29 '16 at 07:44