git diff
One of the most useful commands I use daily is a tool to find changes between branches, help manage pending changes, or merge changes to principal branches.
The most particular use that I have done to this command is to find this list of modified files between branches.
git diff branch_a..branch_b --name-status --oneline
Or find the changes on a specific file between branches.
git diff branch_a..branch_b /paht/to/file
git reset --hard
Another useful command is to revert incorrect changes or fix partial changes on a branch. The scenario in which I have been using this command is to revert a specific commit or jump to a particular moment on commit history.
git reset --hard commit_hash
git cherry-pick
Sometimes some features or changes aren't completed but we have some minor fixes or features working and we need to move specifically these changes in our branch, with a cherry-pick we can move one or multiple changes across branches.
git cherry-pick commit_hash_on_origin_branch
git merge --abort
If you find that some merged and unpushed changes are incorrect or incomplete or for another reason, is possible to avoid pushing these changes and restore the branch using the abort command, a really helpful command tool for some corrupt files during merging.
git merge --abort
You can achieve the same result using the following command too.
git reset --hard last_commit_hash_on_branch
git revert -m 1 hash
If your changes are merged and pushed and you find that you missed something or corrupted your branch with the wrong changes possibly making a rollback of this, this is an amazing tool for avoiding moving incomplete or outdated changes to a production environment.
How to use, easy:
git revert -m 1 hash
git fetch --all
One of the most exhausting and tired experiences is finding that your changes are actually on an outdated branch or you are working on a previously renamed or deleted branch, to avoid that, use get fetch to get all updated branch and remote branches from multiples sourcesĀ
git fetch --all