Skip to content

Random Git Notes

References

Git Basics - Tagging

  • https://git-scm.com/book/en/v2/Git-Basics-Tagging

Git Branching - Rebasing

  • https://git-scm.com/book/en/v2/Git-Branching-Rebasing

Clean up commits

This section is related to commands used to clean up commits.

Uncommit but keep changes

credit to this gist from CrookedNumber.

To "uncommit" the last commit from git, but keep the changes, run:

git reset HEAD^

This command will "evict" the commits from the branch and from the index, but leave the working tree around.

If you want to save the commits on a new branch name, then run git branch newbranchname before doing the git reset.

Remove the last commit

To remove the last commit from git, run:

git reset --hard HEAD^

Remove the last n commits

If you are removing multiple commits from the top, run:

git reset --hard HEAD~n

Where n is the number of commits to remove.

Example to remove the last two commits:

git reset --hard HEAD~2

Remove the last n commits on local and remote

To remove the last commit from git, run:

git reset --hard HEAD~n
git push origin -f

Where n is the number of commits to remove.

Example to remove the last two commits on local and remote:

git reset --hard HEAD~2
git push origin -f

Releases and Tags

GitHub Tagging

  • https://www.google.com/search?q=github+create+tag+without+release
  • https://stackoverflow.com/questions/18216991/create-a-tag-in-a-github-repository

Show latest releases with git

  • https://unix.stackexchange.com/questions/502939/how-to-show-latest-releases-git-tag-with-message
  • https://stackoverflow.com/questions/1404796/how-can-i-get-the-latest-tag-name-in-current-branch-in-git
  • https://github.com/orgs/community/discussions/25199
  • https://www.google.com/search?q=github+actions+workflow+to+checkout+latest+release