Skip to content

Instantly share code, notes, and snippets.

@hivivo
Last active November 29, 2018 18:41
Show Gist options
  • Save hivivo/4771b2ceab69be6eedc3e5b8c9f57e5e to your computer and use it in GitHub Desktop.
Save hivivo/4771b2ceab69be6eedc3e5b8c9f57e5e to your computer and use it in GitHub Desktop.
Git operations
# to change the latest commit date
git commit --amend --date "`date -R`"
# to change the latest commit date and author date
GIT_COMMITTER_DATE="`date-R`" git ci --amend --date "`date -R`"
# or
LC_ALL=C GIT_COMMITTER_DATE="$(date)" git commit --amend --no-edit --date "$(date)"
# create patch for specific commit
git format-patch -1 <sha>
# apply the patch
git am < file.patch
# sync a fork
git fetch upstream
git checkout master
git merge upstream/master
# rebase a fork
git fetch upstream
git rebase upstream/master
git push -f origin master
# rewriting the most recent commit message which is already pushed
git commit --amend
git push --force <example-branch>
# undo a hard reset
## more here: https://blog.github.com/2015-06-08-how-to-undo-almost-anything-with-git/
git reflog
# view the diff of a specific commit
git show <commit id>
# git logs
## a list of files modified/added/deleted per commit
git log --name-status
## the diff introduced per commit
git log -p
## all commits containing any change matching the provided regex string (while ignoring case)
git grep -i 'regex' $(git rev-list --all)
## alternative way. more: https://stackoverflow.com/a/12430097
git log -S "string"
git log -G "regex"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment