Some git statements are not commonly used

Tram Ho

Hello everyone, today I would like to share some cool git statements that not everyone knows and take advantage of. I would like to put away the original theory about GIT and go straight to the main point of this article.

1. Git stash

Save the changes

The git stash command is used when you want to save the changes that you have not commit , which is very useful if you are bad at executing the code at the current branch and want to checkout over another branch .

To save all the code in progress, you can use the following command:


The difference between the two git stash save commands above is that: the first stash save will only save files that already exist, if adding option -u will save new files that never existed in the repo.

You can git stash as many times as you like and each time git will save the entire change as an element in a stack .

Redeem change

To view the list of stash you are saving we use the command:

If you want to see the content of the changes, use the option -p :

Or view the specific content of a specific change:

When you want to apply again changes from certain stash:


Delete unnecessary changes

When you want to undo changes and delete changes, the content is stored in the stack :


Or when you want to delete all saved changes:

Note : index is the location of stash . Demo of the results:

2. Git cherry-pick

So when is the git cherry-pick question used?

When you want to bring changes from commit on another branch current branch . The syntax is as follows:

If cherry-pick commit conflict occurs, you just need to fix the conflict and add it to the commit is okay. And if we want to cherry-pick multiple commit we just need to add the following:

After the cherry-pick completed, push the code up as usual.

3. Git rebase -i HEAD ~ n

If the project you are working on makes a single pull request only one commit while you push multiple commit , this command will help you do that.

First try to log to see how many commits you currently have:

After observing how many commits we now take this important step:

Then it will display the screen as below:

We will press the insert key, move to the commit to merge, fix the pick to fixup, then we press esc , enter: wq to save the changes. Then continue to push up is okay. Achievements after aggregation:

Above are my share, hope to help you. If anyone has any more interesting command, please comment below to share your knowledge. Thank you.

Share the news now

Source : Viblo