Pew Pew Laser Blog

Code. Glass art. Games. Baking. Cats. From Seattle, Washington and various sundry satellite locations.

Blogs about git

Git History.

11.2.2016

Want to take a spin in the good old git time machine? Here are some useful ways to do that.

git show --name-only [sha]
Show which files have changed between the referenced [sha] and the current HEAD.
git log --grep=[stuff]
Show any commits where the commit message matches the regular expression [stuff].
git log -p [filename]
Show the log (commits and changes) for a the file [filename]. You can add any log arguments to this, such as 25 for only the most recent entries in the log: git log -p -25 README.md.
git grep [stuff]
Use the power of git to search for any matches of the regular expression [stuff] in the repo.

Piping Output

Git Tips - Diff.

2.22.2016

Let's talk about how to refer to previous commits absolutely using a hash/sha; or relative to your working directory, master, or previous commits.

Here's quick reference on some cool things you can do with Git's diff command:

git diff
The standard form of git diff will show all differences between your current working directory and the index (the files that Git is watching and has staged for your next commit).
git diff --cached
Just the differences that you've staged (files added to the index); what you would be committing if you run "git commit" without "-a" option.
git diff --name-only
Show just the names of files that are different between your working directory and the index (last commit). Or, pass in two hashes to compare files from those two commits.
git diff master --name-only
Show all files changed between master and your current working directory. This is great for reviewing what changed files you're actually going to commit.
git diff HEAD
Both staged and unstaged changes in your repo; what you would be committing if you run git commit -all.
git diff HEAD~1
Compare current files to the ones from the previous commit. Also git diff HEAD^ HEAD.
git diff HEAD master [file]
Show differences between the working directory and master for one file.
git diff [hash]
Diff between current and previous commit.

Note that hash is that long string which identifies a commit if you do git log.

Git Diff.

1.23.2014

Here are some useful git diff commands:

git diff --name-only
Show names of files that are different between the index (your watched files) and your last commit. Or, pass in two hashes to compare files from those two hashes.
git diff master --name-only
Show all files changed between master and your current working directory. This is great for reviewing changes you'll be making when you merge to master.
git show --name-only [sha]
Show the commit log, and which files have changed in a given hash.
git diff master [filename]
Show the differences between the working directory and master for the file specified.

Git Tips - Commits and History.

11.12.2013

Here are a few things for working with commits and previous file versions.

git add -A git revert [sha]
The above block is 2 sequential git commands. First, add all file changes to Git's watchlist. Roll back to the previous commit, throwing away all changes that you haven't yet committed.
git checkout -b [branch-name] [sha]
Check out an old commit to a new branch so that you can fiddle with it.
git checkout origin/master -- [file]
Replace the current working directory version of that file with the one from master. This is great for reverting a bunch of changes.
git add -A git stash
These two commands which will allow you to save your work in the middle of a commit, and come back to it later. In detail:
  1. Save all changed, added and deleted files to the index
  2. Save that work into a magic "stash".
Now you can do whatever you need to do next, such as checkout another branch or switch projects. When you're ready to come back to your stashed work: git stash pop
git stash list
List all of the stuff you've previously stashed.
git stash apply --index
Applies your most recently stashed work back to your working index. You must also git stash drop [stash name] to remove that particular stash from the list of stashed stuff. git stash pop as used above just handles all of this for you.

Quick and Dirty Git Tricks 2.

8.4.2013

Here are some more handy git commands, which I use frequently.

git checkout -b [new-branch]
Create a new branch, check it out, and move all un-staged changes into that new branch. This is perfect for when you've just started some changes, and then remembered that these changes should really go into their own branch.
git add -A
Add all changed, added and deleted files in path to repo.
git checkout [filename]
Throw away any uncommitted changes to a file by getting a new one from index.
git show [hash]
Details about a commit, including files changed and the actual changes. [hash] should be the actual ID of the commit, which you can get from git log.

More blogs about git: