As all those of us involved in the field of Computer Science know or should know, Git is by far the most widely used modern version control system in the world today. We utilized it in our everyday routine to keep track of our code changes and helps us to work with other developers simultaneously and independently.
Although modern IDE and various tools provided by GitHub, Atlassian and other provide us an easy to use way to perform many git commands nothing compares to the power a terminal provides. Bellow you can find a list of my top git commands.
Rename latest's commit message
# This will pop up an editor window allowing us to pass the new commit message
git commit -amend
# This will not pop up the editor
git commit -amend -m "Your new commit message"
Add file(s) into the latest commit. This requires that last change is not yet pushed into remote
# Add the file
git add the_file_you_want_to_add
# Amend without changing commit message
git commit --amend --no-edit
Reset to specific commit hash and discard any changes since that hash
git reset --hard <commit-hash>
Apply a commit from one branch to another
git cherry-pick <commit-hash>
Show commit logs and limit the output
git log -n <number>
# example git log -n 3
# or
git log -<number>
# example git log -3
If you are aware of any useful / useful git command and want to share it please do not hesitate to leave a comment!
Top comments (0)