Skip to content

Instantly share code, notes, and snippets.

@srikanthmanda
Last active May 22, 2021 15:20
Show Gist options
  • Save srikanthmanda/c74a85b457500063752e8332640aa103 to your computer and use it in GitHub Desktop.
Save srikanthmanda/c74a85b457500063752e8332640aa103 to your computer and use it in GitHub Desktop.
Git Tips

Git Tips

Amend a Commit

git commit -a -m "wrong commit, needs changes"    # commit only staged changes, miss untracked changes
git add forgotten_file edited_file ...            # stage the changes to fix previous commit
git commit --amend --no-edit                      # commit staged changes, without editing commit message
git commit --amend -m "revised commit message"    # edit commit message, and commits staged changes if any

git commit --amend --reset-author                 # revise commit author info (for when committed as wrong user)

Bypass Pre-commit Hooks

git commit --no-verify    # bypasses commit-msg hooks too

Configure User

git config user.name="John Doe"                  # add --global flag for global configuration
git config user.email="jd@example.com"           # add --global flag for global configuration

git config author.name="John Doe"                # for use when author is a different user
git config author.email="mail@example.com"       # for use when author is a different user

git config committer.name="John Doe"             # for use when committer is a different user
git config committer.email="mail@example.com     # for use when committer is a different user

GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, GIT_COMMITTER_NAME, GIT_COMMITTER_EMAIL and EMAIL environment variables override above settings.

Undo a Commit

  • revert creates new commit(s) to undo commit(s).
  • reset discards a commit.

Following command discards the last commit completely.

git reset --hard HEAD~1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment