Structure of the Commit

2

I would like to know if you can change the structure of a commit, in the case before it is made a predetermined structure, example:

GIT_AUTHOR_NAME = '$name(Previamente registrado)'
GIT_AUTHOR_DATE = '$date(data do sistema)'
GIT_COMMITTER_DATE = '$date(data do sistema)'

From this, when you commit, you automatically change the time to the system where the repository is, not the source system. Is it possible to pre-determine these things through a pre-commit?

    
asked by anonymous 30.06.2016 / 17:00

1 answer

2

Git, by default, saves the Unix timestamp (the number of seconds of this 1970) and the timezone (specifically, the offset ) in which the user is currently committed.

For example, a commit right now would make the Git saved the commit with the following information:

commit c00c61e48a5s69db5ee4976h825b521ha5bx9f5d
Author: Seu Nome <[email protected]>
Date:   Fri Dec 14 09:22:00 2018 -0200 # Horário local e offset. Estou no horário de versão brasileiro, caso contrário seria -0300

Mensagem de commit aqui

What you want is to use the local and offset of the repository location and not the user's machine. So, let's say the server repository is in UTC (offset ).

You can even manually specify the date in the commit, using the ISO 8601 format:

git commit --date=2018-12-14T01:00:00+0000

But it is not feasible to do this with every commit. The best way is to do this automatically. So you can get this current date using the date command in ISO 8601 format in UTC and go to the git commit command like this:

git commit --date="$(date --utc +%Y-%m-%dT%H:%M:%S%z)"

In order not to have to use this command every time, you can create an alias for this entire commit command and always use it:

git config --global alias.utccommit '!git commit --date="$(date --utc +%Y-%m-%dT%H:%M:%S%z)"'

And to commit:

git utccommit -m "Mensagem de commit com data em UTC, igual do repositório"

Now, if you really want to use Git's Hook by reading documentation I have not found an easy way to do it . I understand that it would be possible to use the post-commit hook, catch the last local commit (the commit just made) and change the date, using some hook script like this .

    
14.12.2018 / 15:35