Squash commit

Info

Purpose: Combine N commit into one, and make it for new message

Reference resource

Method 1: rebase with -i flag

git rebase -i <hash-id-you-want-to-squash>

Tip

Change the secondary commit from pick to squash, save and continue for set new message for commit

center

center

center

Method 2: reset with --soft flag

git reset --soft <hash-id-you-want-to-squash

center

git commit -m "New message represent for twice or N commit"

center

Delete branch

Info

Follow the article to understand how we can remove the branch in local and remote, use -d flag at: Git Delete Remote Branch – How to Remove a Remote Branch in Git

For locally

You can use -d with command git branch

# e.g: you want to delete release-v1 branch
git branch -D release-v1 # For delete branch
git branch -d release-v1 # For fully merged branch

For remote

You can use -d with command push

# e.g: you want to delete release-v1 branch, but not locally, but remotely
git push origin -d release-v1

Change commit contents

Info

When you want make a change inside your commit, git give us permission to handle it with --amend and option attaching

Change author of commit

You can change author for commit with flag --author with commit command

git commit --amend --author="Author Name <email@address.com>" --no-edit

Change message

And you can take it with new message with flag --message or -m with commit amend

git commit --amend --message "Hello_world"

Tagging commit

Info

git command support us release commit inside some repository platform, such as github, gitlab through using tagging with commit.

If you want explore more about this topic, here are some articles for you

Tagging one commit with annotate

When you want tagging in current commit, you can run tag with -a for annotate and -m for message

# NOTE: Use can asign tag with format v0.0.x or ver0.0.x. But notice about platform for compatible tagging
git tag -a <tag> -m "message if tag"

If you want to specific commit, add commit SHA in last command above

git tag -a 0.0.1 -m "message" 6706483

Rename tagging for old tags

You can read the question - How do you rename a Git tag? to understand how can we handle this case

git tag new old           # Create a new local tag named `new` from tag `old`.
git tag -d old            # Delete local tag `old`.
git push origin new :old  # Push `new` to your remote named "origin", and delete tag `old` on origin (by pushing an empty tag name to it).

Force edit tagging

If you want to keep same context of tag, but change it to new commit or new message, you can handle it with -f option with below command

# Change new commit
git tag -a -f 0.0.1 <new-commit>
 
# Change new message
git tag <tag name> <tag name>^{} -f -m "<new message>"

Share tagging (release)

Info

You can handle share tagging with push command through two way

Push with both branch, and tagging

git push -u origin brach-commig --tags 0.0.1

Or you can push only tag to remote

git push -u origin 0.0.1

Note

Reason why we can, because your tag and branch will separate, and push same or not, it’s does matter

View Tagging

You can review your tag, content inside or what commit it attaching with through various commands

# Review your git tag
git tag
 
# View your git tag with specific expression
git tag -l *-rc*
 
# View your git tag with colume display
git tag --column <always/column/row/dense/...>
 
# View detail change in tag
git show tag-name