Hey there! I’m Srebalaji. You are receiving this email because you have subscribed to level up your game in Git.
Select particular files from git stash
git checkout <stash_id> -- <file_path>
Example
git checkout stash@{1} -- main.rb
Selecting particular files from git stash is a very useful feature.
As mentioned in the above command, you have to checkout to a stash with particular file paths available in the stash.
How to create an empty commit
git commit --allow-empty -m <commit_msg>
Example
git commit --allow-empty -m "Trigger notification"
The empty commit has no files to track.
You may wonder why to create an empty commit. Sometimes you may need to trigger some deployment or you need to test some integration. So pushing an empty commit can do the magic here.
List all branches ordered by most recent commits
git branch --sort=committerdate
The above command will list branches in order of the most recent commits. So you can see branches that you are using it most in recent times.
Very helpful command and it comes in handy when you are working with multiple branches.
Showing diff between branches
We have already seen this command in two of our previous issues.
git log master..develop
This command will help you show all the commits from develop but that are not present in the master branch. In this way, you can know that how many new commits are added to the develop branch that is not present in the master branch. And make sure you have the updated changes in the local before comparing.
How to mark a commit as a fix of previous commit
git commit --fixup <commit-hash>
Example
git commit --fixup 30b6c97
Fixup option helps you to create a commit which will be considered as a fix of the previous commit.
In the above image you can see how the latest commit is created as fixup as the previous commit.
I know you can use rebase or amend to fix the previous commit. But there is a possibility that you have pushed the code and may not be in the position to force push it.
That’s it for today :)
See you next week :) :)