How I Learned to Trade Perfectionism For Progress

It is clear to most people that perfectionism sucks. It sucks for the perfectionists, and it sucks for everyone around them. In the words of Jaron Lanier, “Seeking perfection in human affairs is a…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




8 Git commands you may not know

From programmers to IT professionals, all software developer these days is using Git, the most famous version control system around. In this blog, you’ll learn Eight (8) Git commands that you may have not used it before.

There may be possibility that you may have used, some may be new to you, and some you might think there’s no way this is going to work. But you’ll never know until you try them out!

Mostly when committing, we hit “Enter” so quickly, and sometimes that leads a typo somewhere in the commit message. Let’s fix this.

In this example, let’s say we run git commit -m “Corrected the typeo” and hit “Enter.” Immediately we realize that we mislabeled the commit message, so now we need to fix the “typeo” in the commit message..

Running the command git commit --amend -m "Corrected the typo" does the magic. Now when we push our commit, our fellow team won’t see that our "typo" misspelled.

This command is for uncommitted changes in a file. The stash operation takes your revised tracked files, stages changes, and saves them on a stack of unfinished changes that you can reapply at any time in the future.

Suppose we have a bunch of changes to a file but demand to go back and test something out before we commit and push this, or we’re just not ready to commit our changes. That’s where git stash comes into picture.

The git reset command is a complex and handy tool for undoing changes. It has three primary forms of invocation. These forms correspond to command-line arguments --soft, --mixed, --hard, let’s chat about the "soft" trailing.

The command git reset —soft HEAD~1, is going to remove the last commit from the current branch. But the best thing about this command is that the changes won’t fade! All the changes will stay in the working tree!

In this example, we committed and then ran the command git reset —soft HEAD~1. Trying to push this commit will not work, so when git push origin master ran, there was nothing there to push. It certainly took our last commit and kept our changes in the corresponding file!

We have often used the command git add <file> or git add . in the past. But what does git add -p do? 🤔

Well, here this command does just that. It provides for a more concise commit. Once this command runs, we’ll be asked about “hunks.” “Hunks” are the chunks of code that we’ll decide what to do with.

You’ll see the question, “Stage this hunk [y, n, g, a, d, e, ?]?” at the bottom of the terminal.

The letters mean the following things:

When completed with all the “hunks,” we will be able to see that our commit is ready, and we can proceed to the push!

Cherry-picking in Git stands for attempting some commit from one branch into another branch. In this command, we can choose a particular branch that has a commit and pull it into another. Let’s walk through this.

Suppose you are working on a project where you are making changes in a branch called new-features. You have already made a few commits but want to move just one of them into the master branch.

By using the command, git cherry-pick rowdymehul-test, we can get that entire commit into another branch.

Now, Checkout the branch where you want to cherry-pick the specific commits. In this case master branch:

Bring a whole commit from one branch into another.

This command can benefit so much when there’s a many going on in a commit, and you would rather not commit the entire thing. It’s like git cherry-pick (which we just talked above), but rather than “cherry-picking” an entire commit, we are dipping even deeper into a branch and picking just a particular file that we want to be merged. Let’s see how magic’s done!

While sitting in master the whole time, we can run the command git checkout demo checkout.html to grab that particular committed file in that specific branch and bring it over to master to push eventually. That’s pretty clear when a specific branch’s changes are many, and we’re only looking for one file to test or push.

We mostly use the ‘git log’ which will show you all commit logs. No doubt that it will give complete details about our commit actions but what when we need short information about our activities.

Here, ‘git shortlog’ will summarize the ‘git log’ output and give you the details in short. Please refer to the following output of both operations.:

There are so numerous different git commands out there. If we were to run just git help <command>, then we would get an explanation of the command right there in our terminal.

Running the command git help -w <command> takes us directly to the browser that we can read up on all the things with the command in question. It will open a web page where you can read the complete details about the specific command that you have mentioned in the command.

Looking for common git commands? Here you go👇

Git is robust version control, and I am sure most of us may use it every day. I hope these 8 secret gems help you be a little more productive in your Git commands. What’s your favorite Git command, which you recently come across? Just comment below and let us know! 🎉

Add a comment

Related posts:

Animals perceive better than humans

Lately I decided to be more measured in the way I interact with Kariya, our cat. Instead of expressing my love I pivoted to giving love when he wanted it only. These seemingly simple changes took a…