How to change the date of a commit before doing 'git push'?

8

I was working ahead because I need free time in the next few days and I have already comiteado the changes to my local repository and pusheado a fork that I have as backup.

Now, regarding the origin, I want to put commits A and B with date of say next Monday (I do not want them to have the original date of the commit).

The same happens with commits C and D, which I want to push on Tuesday, with a date on Tuesday.

Is it possible to do this using git without doing git reset ... and re-committing on Monday and Tuesday respectively?

I understand that there are two parties to this, one would be to change the commit date and the other would be to push only one commit group on Monday and another on Tuesday.

Update:

I can not do a git reset and re-commit using git commit --date because these commits modify the same files and it would not be consistent, next time I'll take it into account.

    
asked by rnrneverdies 20.03.2016 в 00:19
source

1 answer

4
  

(I do not want them to have the original date of the commit)

I think there is a conceptual error here. When "pusheas" you are not "sending to the repository", you are simply synchronizing (perhaps partially) the remote repository with the local one. GIT (unlike CVS or Subversion) is distributed, which means that there is actually only one repository, which is mirrored (perhaps partially) in different places. Therefore, you simply can not push a commit with different data (in this case the date). The repository is the same, the commit is the same.

What you can do is change the date of the commit (local), and then push it:

git filter-branch --env-filter \
    'if [ "$GIT_COMMIT" == "6489982f81797b71534357fa5a442a2604c61eff" ]
         then
                  export GIT_AUTHOR_DATE="2016-03-20T05:57:12-03:00"
                  export GIT_COMMITTER_DATE="2016-03-20T05:57:12-03:00"
     fi'

(copied from here: link ) (change the commit hash and the date-time)

With respect to pushear only some commits, the syntax is:

   git push <remoto> <SHA del commit>:<branch>
    
answered by 20.03.2016 в 18:59