Over the last couple years, Git has become a default part of almost every developer’s knowledge stack. But even though Git is so well-known, there are many Git commands that are not.

In this short post, I’d like to show you seven little commands that can help you become more productive and well-versed with Git. Let’s dive in.

Finding Out What Has Changed in a File

Staying on top of things can be hard – especially if many people work on the same code base.

To help you understand exactly how (as well as when and by whom) a file was changed, you can use the good old git log command – but with a little spice:

$ git log --since="3 weeks" -p index.html

Using “-p” makes sure you see the actual changes as diffs (and not only the commit’s metadata). And the “–since” option helps you zero in on a recent time frame.

Undoing Your Last Commit in Style

Sometimes we think a bunch of changes are ready for committing – but directly after making the commit, we notice that we were too quick.

Changes could be missing, we could have hit the wrong branch, or a multitude of other problems could have happened…

The only thing that’s certain: we’d like to undo this last commit and get our changes back into our Working Copy!

We can use the git reset command with a special set of options:

$ git reset --mixed HEAD~1

The “–mixed” option makes sure that the changes contained in the commits being reset are NOT discarded. Instead, they are preserved as local changes in the Working Copy.

Using the “HEAD~1” notation is a great shortcut to specify “the commit before the latest one” – which is exactly what we want in order to undo the very last commit.

Feel free to read more about this topic in how to undo the last commit.

#git #programming #developer

Git Secrets: 7 Commands You Might Not Know
1.85 GEEK