The Unterminated String

Embedded Things and Software Stuff

Occasionally Useful Git Commands

Posted at — Jun 12, 2020

Git revisions

Not a command, but a useful reference. gitrevisions lists the various ways you can refer to a commit.

Get the history of a function

git log -L :${FUNCTION}:${FILE}

References:

Show a file at specific commit

git show ${COMMIT}:${FILE}

References:

Checkout a file at specific commit

git checkout ${COMMIT} -- ${FILE}

References:

List files changed in git log

git log --name-only
git log --name-status

References:

Display a shortened git log

git log --decorate --oneline --graph

References:

Find last common commit

git merge-base ${COMMIT1} ${COMMIT2}

References:

Find remote branches containing commit

git branch -r --contains ${COMMIT}

References:

Reword an annotated tag

git tag -a -f ${TAG} ${TAG}^{}

References:

Get just the sha1

git rev-parse ${COMMIT}

References:

Move a series of commits onto a new branch

git rebase --onto ${NEW_BASE_COMMIT} ${OLD_BASE_COMMIT} ${BRANCH_NAME}

References:

Remove a file from the last commit

git reset --soft HEAD~1
git reset HEAD ${FILE}
git commit -c ORIG_HEAD

References:

Create a commit without file changes

git commit --allow-empty

References: