سؤال

Is there a way to protect a given git commit from being amended?

All I can think to do is to write a pre-commit hook to check the SHA against a list of 'non-amendable' SHAs. Does anyone know of a standard/better way?

Thanks.

هل كانت مفيدة؟

المحلول 2

You can consider signing your commit with a GPG key.

In order to do so

  • Add your GPG key as a signing key

    git config --global user.signingkey YOUR-KEY
    
  • Commit using the -S option

    git commit -S -m "Your commit message"
    

نصائح أخرى

You can tag commits using a private key so that if the commit is amended no one without the key can sign the new commit.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top