My favorites | Sign in
Project Home Downloads Wiki Issues Code Search
Search
for
GitTips  
Tips for using Git
git
Updated Jul 25, 2013 by [email protected]

When UsingGit, there are a few tips that are particularly useful when working on the Chromium codebase, especially due to its size.

See also GitCookbook.

Remember the basic git convention:

git COMMAND [FLAGS] [ARGUMENTS]
Various git commands have underlying executable with a hyphenated name, such as git-grep, but these can also be called via the git wrapper script as git grep (and man should work either way too).

Git references

The following resources can provide background on how Git works:

  • Git-SVN Crash Course -- this crash course is useful for Subversion users switching to Git.
  • Think Like (a) Git -- does a great job of explaining the main purpose of Git's operations.
  • Git User's Manual -- a great resource to learn more about how to use Git properly.
  • A Visual Git Reference -- a resource that explains various Git operations for visual reasons.
  • Git Cheat Sheet -- now that you understand Git, here's a cheat sheet to quickly remind you of all the commands you need.

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. 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')

Diffs

 git diff --shortstat

Displays summary statistics, such as:

 2104 files changed, 9309 insertions(+), 9309 deletions(-)

Sign in to add a comment
Powered by Google Project Hosting