利用者:Brita/Configs/Git

提供: wiki
移動先: 案内検索

Git configuration

These are my git-related configurations and tips. Feel free to use what you like, but please don't copy my name or email to your settings :)

I have most of my configurations at ~/.gitconfig . This is where settings end up when they are set with --global from the command line. These configs apply to blender and all the other projects I work on.

I have settings specific to blender at ~/blender-source/.git/config . Settings placed here do not affect other git projects and can override the global settings. To set options for the blender project only from the command line, don't pass --global or --system.


~/.gitconfig - contains my commit information, aliases and colors

[user]
	name = Ines Almeida
	email = non-blender@mail.com
[core]
	editor = pico
[alias]
	ci = commit
	co = checkout
	rb = rebase -i
	br = branch
	st = status
	df = diff
	undo = reset --soft HEAD^
	#show the log of diffs for a file >> git fdiff source.c
	fdiff = log -u
	#diff a specific revision against it's parent >> git diffr hash
	diffr  = "!f() { git diff "$1"^.."$1"; }; f"
	lg = log --graph --pretty=tformat:'%h %C(cyan)[%ar]%C(reset)%Cgreen%d%Creset %s - %C(yellow dim)%an%C(reset)' --all --since
[color]
	ui = true
	# colors and presentation options:
	# - normal, black, red, green, yellow, blue, magenta, cyan, or white
	# - bold, dim, ul, blink, and reverse

[color "branch"]
	#current, local, remote (a remote-tracking branch in refs/remotes/),
	#upstream (upstream tracking branch), plain (other refs).
	current = white reverse
	local = white

#[color "decorate"]
	#branch, remoteBranch, tag, stash or HEAD for local branches, 
	#remote-tracking branches, tags, stash and HEAD, respectively.

#[color "grep"]
	#http://git-scm.com/docs/git-config

#[color "interactive"]
	#prompt, header, help or error,

[color "diff"]
	#plain (context text), meta (metainformation), frag (hunk header), 
	#func (function in hunk header), old (removed lines), new (added lines), 
	#commit (commit headers), or whitespace (highlighting whitespace errors).
	meta = yellow bold
	frag = white dim
	func = white ul
	old = red
	new = green
	whitespace = yellow reverse

[color "status"]
	#header, added or updated (but not committed), changed (but not added in the
	#index), untracked, branch, or nobranch
	added = green
	changed = yellow
	untracked = red


~/blender-git/blender/.git/config - this is what I *added*

[user]
	email = britalmeida@gmail.com
[pull]
	rebase = true
[alias]
	pullb = "!git pull;git submodule foreach git pull origin master"
	fs = submodule foreach git
	pushs = log origin/master..master
	lg = log --graph --pretty=tformat:'%h %C(cyan)[%ar]%C(reset)%Cgreen%d%Creset %s - %C(yellow dim)%an%C(reset)' --all --since 2days
        lgme = log --graph --pretty=tformat:'%h %C(cyan)[%ar]%C(reset)%Cgreen%d%Creset %s - %C(yellow dim)%an%C(reset)' --all --since 1week --author Ines
        socmerge = "!git fetch;git submodule foreach git pull origin master;git merge origin/master"

Settings like my email override the ones I defined in the global config file. The alias 'lg' is also being reset.

  • 'lg' prints the commit version log in a legible form (in my opinion) and constrains it to 2days. '2days' can be removed from the definition for flexibility, in which case the command should be used like 'git lg 3days' instead of 'git lg'.
  • 'lgme' shows my weekly progress, it is useful to build reports
  • 'pullb' is a short for the recommended way of pulling (note that I have pull with rebase set to true):
git pull
git submodule foreach git pull origin master
  • 'socmerge' fetches and merges from master into the branch I am currently working on (in this case the soc branch)
  • 'pushs' shows a log of commits to be pushed
  • 'fs' executes a command foreach submodule. The usage is: 'git fs pull' or 'git fs pushs', etc.

From Campbell:

Find out what I did over the last week - using media-wiki syntax for GitCommit & BugReport (nice for writing weekly logs)

git log --stat --decorate --format="%C(yellow){{GitCommit|%h}}%n%C(green) %B%Creset" --author="Campbell Barton" --since=1.weeks | perl -e "s/\bT(\d+)\b/\{\{BugReport\|\$1\}\}/" -pi

Aggressive gc, (remove rubbish from stashes and deleted branches)

git -c gc.reflogExpire=0 -c gc.reflogExpireUnreachable=0 -c gc.rerereresolved=0 -c gc.rerereunresolved=0 -c gc.pruneExpire=now gc --aggressive


Debugging with bisect

To search for a change that introduced a problem, git offers an utility for binary search. For this to be quick, it is a good idea to disable most options on the build configuration.

  git bisect start
  git bisect bad ##current version has the problem
  git bisect good v2.69 ##tags and hashes can be used

git will now present the revision in the middle of the good and bad one. Compile, test, and tell git if it is a good or bad one:

  git bisect [good|bad]

In the end, to cleanup the bisect state:

  git bisect reset