-
Notifications
You must be signed in to change notification settings - Fork 7
/
git.txt
164 lines (131 loc) · 4.18 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# Adding local repository to GitHub
Create new repository on GitHub
git remote add origin https://github.com/cangermueller/deepcpg2.git
git push -u origin master
# Storing user,pass,auth
git config credential.helper store
# Merging
<<<<<<< HEAD
Stuff in own branch
=======
Stuff in merged branch
>>>>>>> ca35f63885df20778cad7a40c9e26e222c380ee2
# Branches
checkout -b new_branch // create and switch to new branch from current one
checkout HEAD~2 -b new_branch // checkout certain version as new branch
checkout 213123 // checkout in temp branch
branch -m new // rename current branch to new
branch -d name // delete branch
branch -dr origin/keras2 // delete remote branch locally
push origin --delete keras2 // delete remote branch on github
# Misc
status -u // show untracked files
add -f *.pdf // add .gitignore files
git checkout-index -a -f --prefix=/path/ // checkout current branch to dir
# Ignoring files
.gitignore // shared
.git/info/exclude // not shared
## Pattern
name
dir/
/dir_at_root/
**/sub_dir/**
# Remote repository
remote // show remote branches
remote show hpc // show infos about remote hpc
remote add name url
remote remove NAME // delete remote rep. and all branches
fetch name // update local branches -> see branch -r
push name src_branch:dst_branch
push name master:child/master // push master to name/child/master
push name master:refs/remotes/X/master // push to remote branch X/master on name
push -u name r1:sync/r2
* push r1 to sync/r2 on name
* set upstream information -> pull will use name sync/r2
push name --delete branch // delete remote branch
pull name master // pull master from name
## Different pull / push branches
[branch "master"]
remote = hpc
merge = refs/heads/sync/master
[remote "hpc"]
url = hpc:~/research/bs/dev/160921_deepcpg-dev/src
fetch = +refs/heads/*:refs/remotes/hpc/*
# Undo changes
git checkout file.py // single file
git reset --hard // all changes
# Commit messages
file.h: fix bug at line 88
Fix bug at line 88 caused by division of zero.
* Imperative, present
* First line
* file: update changes
* title
* no full stop
* present, imparative
* < 50 characters
* Whitespace
* Description
* Present, imperative
* <50 characters
# Nested repository
/main_rep
git clone src nested_rep
* main_rep ignores nested_rep
* nested_rep is independent of main_rep
* nested_rep has own .git
* git clone main_rep does not clone nested_rep
<-> submodules
* nested_rep does not have .git
* submodules can be checked out from main_rep
# Submodules
## git submodule CMD
* status // status information
* init // add entry for all modules in .gitmodules to .git/config
* update // checkout head
* .git/modules // configuration files, e.g. info/exclude
## Checkout all submodule
* git clone --recurse-submodules
* git submodule init
* git submodule update
## Addding fresh submodule
* git submodule add git://github.com... [PATH]
* git commit
## Addding checked out submodule: exactly the same as before!
* git submodule add git://github.com... [PATH]
* git commit
## Removing submodule
https://gist.github.com/myusuf3/7f645819ded92bda6677
# tag
tag -a -m 'First version' v0.1 // create annotated tag with message -m
-l -n [1] // show first line of annotation
git push --tags
# describe
describe // show description of current tag
# checkout branches and files
log // show last commits
checkout ID // checkout branch in tmp branch
checkout -B tmp ID // checkout branch in new branch tmp
checkout ID -- file // checkout single file into current branch
# rebase
## idea
A - B - master
\
develop
develop is checked out:
git fetch upstream
git rebase upstream/master
A - B - master
\
develop
more transparent than merge:
http://stackoverflow.com/questions/16666089/whats-the-difference-between-git-merge-and-git-rebase
* git push -f origin branch // overwrite changes after rebase
## interactive rebase
* to skip, merge, amend past commits
* http://stackoverflow.com/questions/495345/removing-selected-commit-log-entries-for-a-git-repository
git rebase -i HEAD~5 // HEAD~5 point to last clean commit before change
git rebase --abort
git rebase --continue
# Diff
diff branch1..branch2 // diff between branches