Git Cheat Sheet -- now that you understand Git, here's a cheat sheet to quickly remind you of all the commands you need.

Configuring the output of “git log”

By default, the date that “git log” displays is the “author date.” In Chromium, this generally corresponds to the date that the committed patch was last uploaded. In most cases, however, the date that is of interest is the date that the patch was committed in the tree. To configure “git log” to instead display the latter date for your Chromium checkout, execute the following command:

If you want to change all your repos (e.g., because you have multiple Chromium checkouts and don't care about having the default for other repos), add “--global” after “config” in the above command.

Committing changes

For a simple workflow (always commit all changed files, don't keep local revisions), the following script handles check; you may wish to call it gci (git commit) or similar.

Amending a single revision is generally easier for various reasons, notably for rebasing and for checking that CLs have been committed. However, if you don't use local revisions (a local branch with multiple revisions), you should make sure to upload revisions periodically to code review if you ever need to go to an old version of a CL.

Searching

Use git-grep instead of grep and git-ls-files instead of find, as these search only files in the index or tracked files in the work tree, rather than all files in the work tree.

Note that git-ls-files is rather simpler than find, so you'll often need to use xargs instead of -exec if you want to process matching files.

Global changes

To make global changes across the source tree, it‘s often easiest to use sed with git-ls-files, using -i for in-place changing (this is generally safe, as we don’t use symlinks much, but there are few places that do). Remember that you don't need to use xargs, since sed can take multiple input files. E.g., to strip trailing whitespace from C++ and header files:

sed -i -E 's/\s+$//' $(git ls-files '*.cpp' '*.h')

You may also find git-grep useful for limiting the scope of your changes, using -l for listing files.

sed -i -E '...' $(git grep -lw Foo '*.cpp' '*.h')

Remember that you can restrict sed actions to matching (or non-matching) lines. For example, to skip lines with a line comment, use the following: