[toc]
Configuration
git config --global user.name "John Doe"
git config --global user.email "johndoe@bidon.ca"
git config --list
Diff, log
git show [hash]
git show [tag]
Only for a given file:
git show [hash] path/to/file
Show revision tree:
git log --all --graph --decorate --oneline
Branches
Checkout a specific branch:
git checkout name-of-branch
Create a branch:
git checkout -b name-of-branch
Patches
Check if it applies cleanly:
git apply --check /tmp/foo.patch
Apply the patch:
git apply /tmp/foo.patch
For drupal.org, attribute a commit to the patch author (replace with correct 'username' and numeric user ID):
git commit --author="username <username@1234567.no-reply.drupal.org>"
If the patch was created by "format-patch" (contains author information):
git am /tmp/foo.patch
More information: [http://progit.org/book/ch5-3.html](Pro Git: Maintaining a Project), page 130
Merge a git repository in a sub-directory
In weird cases where you have your main repository and want to import a sub-repo into your main one:
cd ./other/repo/
mkdir templates
git mv CRM templates/
git commit -m "moving to templates subdir" -a
git filter-branch --index-filter \
'git ls-files -s | sed "s-CRM/-templates/CRM/-" | GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
git update-index --index-info &&
mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD
Then move back to the root of your main git repository and pull:
cd ../../
git pull
The delete the .git in "other/repo/.git".
Books
- http://book.git-scm.com/ - community book
- [http://progit.org/book/](progit.org/book/] - Pro Git by Scott Chaon, excellent book