Showing entries with tag "Git".

Found 5 entries

Git: Show all commits that affect a certain line

I found a bug on a particular line, and need to track down the history for that line. This is easy enough with git blame, but in this case I'm getting false positives. There was a previous check-in that changed whitespace on that line. Obviously that was not the commit that introduced the bug.

Using git log with the -L flag you can specify a file and and range of lines to search through.

git log -L 57,57:index.php

This will show all the commits in index.php where there was a change on line #57.

See also: Finding commits that match a search term

Leave A Reply

Git: Finding all commits that match a given line

If you need to show all the commits that modify a specific line you can use git log and the -G flag like this:

git log -G "version" docs/release_history.txt

This will show every commit that contains "version" in one of the modified lines anywhere the file /docs/release_history.txt

Leave A Reply

Git: Show changes made today or yesterday

I found two cool Git aliases that will show you all the commits that have been made today or yesterday. It's a simple way to figure out what you accomplished.

Define the aliases:

git config --global alias.today "log --since=midnight --oneline --graph --decorate"
git config --global alias.yesterday "log --after=yesterday.midnight --before 0am --oneline --graph --decorate"

Then run it with:

git today
git yesterday

I borrowed the idea from Coderwall.

Leave A Reply

Git: Create a new local branch and set up remote tracking

If you want to create a new branch in Git, and set it up so it's tracked upstream also do this:

git checkout -b branch_name
git push -u origin branch_name

git push -u handles setting the upstream, as well as setting the local branch to track the remote branch.

Leave A Reply

Git: Find the branch that a given commit landed on

If you need to find the branch that a commit was checked in to use the following command:

git branch --contains 26495cfd4ab17d4d685d0d352ed333f73d6d1b96

This should show a list of branches, with the respective branched highlighted and preceed with an asterisk.

Leave A Reply