Git Scraps

Types of HEAD

NameMeaning
HEADThe latest commit
ORIG_HEADOne commit before the latest
FETCH_HEADThe latest commit of the remote branch
MERGE_HEADThe latest commit of the merged target

Tips

git push origin HEAD

This pushes the current branch, which is convenient.

Reverting to a Specific Commit

  • ${hash}: A specific commit
  • ${dirname}: A directory name
  • ${file_n}: A file name
# Entire repository
git checkout ${hash}

# A specific directory
git checkout ${hash} ${dirname}

# Specific files
git checkout ${hash} ${file_1} ${file_2}

Reset Operations

# Undo add
git reset --mixed HEAD
# Undo commit
git reset --soft HEAD^
# Delete the last commit
git reset --hard HEAD^
# Discard changes after commit
git reset --hard HEAD
# Undo the last reset
git reset --hard ORIG_HEAD
# Overwrite with the remote branch's HEAD (e.g., when you accidentally amended and pushed)
git reset origin/${branch_name}

reflog

A useful subcommand when you accidentally run git reset. reflog is a list of commits that HEAD has pointed to, and it is stored locally only. By default, reflog entries are deleted after 90 days. Since it is local-specific, it is not retained on the remote side.

git push Freezes

unset SSH_ASKPASS && unset GIT_ASKPASS

Resetting git credentials

Change --local or --system as needed.

git config --global --unset credential.helper

Getting the Current Branch Name

git symbolic-ref --short HEAD

Create an issue on GitHub about this article

Read Next