Dev Notes Dev Notes
  • Home
  • Categories
  • Tags
  • Archives

Some git tips to make your life easy

Git

Update last commit

git commit --amend

Revert last commit

$ git commit -m "Something terribly misguided"              (1)
$ git reset --soft HEAD~                                    (2)
<< edit files as necessary >>                               (3)
$ git add ...                                               (4)
$ git commit -c ORIG_HEAD                                   (5)

Source: Stackoverflow

Update author & email in your previous commits

Update author for all your commits:

git filter-branch -f --env-filter "GIT_AUTHOR_NAME='Mobile Developer'; GIT_AUTHOR_EMAIL='your_mail@gmail.com'; GIT_COMMITTER_NAME='Mobile Developer'; GIT_COMMITTER_EMAIL='app.mobile.developer@gmail.com';" HEAD

Source: Stackoverflow

Commit in the past (with date)

git commit --date="`date --date='2 day ago'`" -am "update"
git commit --date=”Wed Feb 16 14:00 2037 +0100”

Check author and commiter dates:

git log --date-order --date=iso --pretty=format:’Author Date[%ad] Committer Date [%cd]‘
Option Variable Name Description
author date GIT_AUTHOR_DATE notes when this commit was originally made
commit date GIT_COMMITTER_DATE gets changed every time the commit is being modified

In git log you see author date:

commit b9195931207eaaf8763c585595e6347542e9261d
Author: Mobile Developer <app.mobile.developer@gmail.com>
Date:   Wed Nov 11 17:34:35 2015 -0800
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        Author Date

To check author and committer dates use following command:

git log --date-order --date=iso --pretty=format:’Author Date[%ad] Committer Date [%cd]‘

GIT_AUTHOR_DATE=$(date -v-5d) GIT_COMMITTER_DATE=$(date -v-5d) git commit -m "Added Additionals headers"

Summary

Option Description
Update last commit git commit --amend
Commit in past git commit --date="date --date='2 day ago'" -am "update"
Revert last commit git reset --soft HEAD~

Sources:

Stackoverflow

Git documentation


Published

May 18, 2016

Last Updated

May 18, 2016

Category

HowTo

Tags

  • git 1

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor