Tag: logs

How to use `git log –first-parent` to only view commits that happened on a given branch – 077

First Parent Only via Visual Studio – View History

By default the View History option in Visual Studio (from Changes – Action – View History or from the Status bar  – <branch name> – View History) shows all commits, regardless whether the commit occurred in a separate branch or on the current branch. Let’s assume master is the current branch for simplicity. I’m using Open Live Writer as an example.

Shout out to http://marcgg.com/blog/2015/08/04/git-first-parent-log/ who has a great write-up on when you’d use –first-parent.

Right now on Twitter, developers are sharing how much they have to look up things. “Hi, my name is Sara. When I look at the Git history graph, I see a praying mantis.”

local history for master branch showing crazy graph

If you only want to see the changes that occurred on master (or whatever branch you are currently viewing the history for), you can click the Show First Parent Only button.

Show First Parent Only

Now you’ll only see commits that occurred directly on the branch itself (and not on another branch that got merged into the current branch).

Local History now a flat graph

Command Line git log –first-parent

Rinse and repeat for command line.

From yesterday’s tip, if you run git log –graph –pretty=oneline –graph –abbrev-commit

git log --graph --pretty=oneline --graph --abbrev-commit

You’ll see all of the commits from different branches.

Now add the –first-parent option at the end: git log –graph –pretty=oneline –graph –abbrev-commit –first-parent

git log --graph --pretty=oneline --graph --abbrev-commit --first-parent

Thanks again to http://marcgg.com/blog/2015/08/04/git-first-parent-log/ for the great description! As I said above, I just see a praying mantis. 🙂

How to view the name and email that is associated with a commit on GitHub via the web browser – 051

Suppose you want to verify your email in your Git logs hosted on GitHub without pulling down the repository.

Navigate to the desired commit (via Code tab – Commits link – Commit)

commit displayed on github

Now in the URL shown in your web browser, add the extension .patch and you’ll see the name and email from your .gitconfig.

printout from a format-patch displayed in plain text

btw, in case you want to know what’s going on, this is actually the git format-patch command, where GitHub is displaying the output.

Since the commit ID is 32473a3, we can do

$ git format-patch 32473a3~1..32473a3

git format-patch 32473a3~1..32473a3

to get the same result in the command line.

showing generated patch file from command line

How to hide your email address in your Git commits but still get contributions to show up on your GitHub profile – 050

I have good news and bad news. Let’s start with the good news.

If you want to get credit for your commits, but don’t want to expose your GitHub email address in the commit logs (have you checked the logs? why haven’t you checked the logs*?), here are the steps you can take. 

contributions graph on GitHub profile

First, in GitHub go to Settings – Email – Keep my email address private

Keep my email address private checkbox

You’ll notice a new email saraford-tips@users.noreply.github.com for you to use for your Git commits.

Next, you’ll need to update Git to use this new noreply email instead of your real one. You can do this either from the command line or from GitHub Desktop.

From the command line, provided that you want to change your email address globally across all repos, you’ll simply do

$ git config –global user.email “your-username@users.noreply.github.com”

and then to verify, type

$ git config –global user.email

for example

git bash showing --global user.email changed

Or if you want to use GitHub Desktop, it’s just at Options – Configure Git which will do the same as the –global flag, hence the red circle around the global gitconfig message.

Configure git username and email address

You can read more in the GitHub Documentation for keeping your email address private, e.g. how to change only a specific repo, etc.

And now for the bad news.

This change will only apply moving forward. If you’ve been using your personal email address in previous Git commits, you’ll need to do some work to scrub the logs (where possible). Check out the GitHub Documentation for changing author info.

*My favorite all-time scary movie is the 1979 version of When a Stranger Calls. Well, not the entire movie, but just the first 15 minutes. And I don’t think it holds up anymore with smart phones being the norm. But wow, that was something scary! And yeah, you should check the logs… just to make sure you don’t have your email address committed that you don’t want others to see.