-
Notifications
You must be signed in to change notification settings - Fork 1
/
git.txt
120 lines (88 loc) · 4.06 KB
/
git.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
pruning your local remote branch references
* git remote prune origin #where origin is the remote name, removes and references your local git repo has to remotes that have since been deleted. i.e. cleans up invalid remote branch references when you run "git branch -r"
gitignore
# for local ignores not in source control, edit .git/info/excludes
submodules
Setting up
* git clone --recursive git://repo/repo.git clones the repository and initializes and installs all submodules, but doesn't work on older
* so, after cloning git://repo/repo.git run "git submodule update --init"
Adding
* "git submodule add git://repot/subrepo.git ./vendor/plugins/subrepo"
Removing
* edit .gitmodules to remove the desired submodule. then "git rm --cached /path/to/repo" to get it out of the git history. This is important!
git bisect
http://www.kernel.org/pub/software/scm/git/docs/git-bisect-lk2009.html
where did the code go bad?
git bisect - you give it a start that’s good and an end that’s bad, and it goes to the commit halfway in between via binary search. enter ‘git bisect good’ if it’s good or ‘git bisect bad’ if it’s bad. It then goes in between the next good and bad commits until it tells you at which commit it has found to have gone bad. see :http://www.palantir.net/blog/using-git-bisect-fun-and-profit and http://lwn.net/Articles/317154/ (for how to automate it)
.e.g
git bisect start #start the process from the HEAD of the branch
git bisect bad #we’re starting out and it’s bad
git bisect good “commit-id” #we know it was good at this commit hash
.# it’ll take you to a commit in the middle and you tell it ‘git bisect good’ or ‘git bisect bad’, take you to the middle of the next good and bad. iterate this one till done
‘git bisect reset’ #when you found the bug and noted the commit. It then takes you back to HEAD
good luck
interesting commands-------------
git status -sb
git notes edit ad9f487
git describe HEAD@{1.month.ago}
git name-rev ad9f487 --name-only # for helpful commit name sharing
git config --global alias.human "name-rev --name-only --refs=refs/heads/*"
git config --global alias.humin "name-rev --refs=refs/heads/* --stdin" #takes stdin e.g. git log | git humin
git log --oneline --decorate --graph
bundles, sharing commits by email etc.
* git bundle create repo.bundle master
* ls -lh repo.bundle
* git ls-remote repo.bundle
* git clone repo.bundle -b master repo
-- getting local not yet pushed changes
* git log --oneline master ^origin/master
* git bundle create commits.bundle master ^origin/master
* ls -lh commits.bundle
* git fetch ../commits.bundle master:other-master #import it
* git log --oneline --graph --decorate --all
branch fun
git branch
--merged
--no-merged
--contains ad9f487
tracking
* git push -u origin mybranch
* git config --global push.default #can be matching, nothing, tracking, or current
git replacements (have a commit point to another sha1, to separate out history)
* git branch history master~1
* git remote add history git@.../project-history.git
* echo 'get history from... ' > msg
* cat msg | git commit-tree history~1^{tree}
* git rebase --onto 622eab 4fjk893
* git replace adfalj asdflkja;s
* git cat-file -p 348jkl
* git --no-replace-references cat-file -p 348jkl
* git for-each-ref
IMPORTANT
* git config --global rerere.enabled 1
* git merge # resolve, conflict,
* git rerere status
* git rerere diff #shows how conflict resolved
* git commit # records how resolved
* git checkout --conflict=merge hello.rb
* git rerere #resolves it
* git merge --rerere-autoupdate
* git config --global rerere.autoupdate 1
enviroment
GIT_DIR or --git-dir=
GIT_INDEX_FILE
git status -s
git read-tree HEAD
GIT_WORK_TREE
overwriting your credentials
GIT_AUTHOR_NAME
GIT_AUTHOR_EMAIL
ribbit and libgit
git bash completion
cp /usr/local/Cellar/git/<version>/etc/bash_completion.d/git-completion.bash ~/.git-completion.bash
Stick this in your .bash_profile:
# Git tab completion
source ~/.git-completion.bash
# Show branch in status line
PS1='[\W$(__git_ps1 " (%s)")]\$ '
export PROMPT_COMMAND='echo -ne "\033]0;${PWD/#$HOME/~}\007"'