|
1 .. -*- coding: utf-8; -*- |
|
2 |
|
3 ====== |
|
4 Git. |
|
5 ====== |
|
6 |
|
7 Setup git. |
|
8 ========== |
|
9 |
|
10 Debian. |
|
11 ------- |
|
12 |
|
13 For Etch Degian release use git-core package from backports, |
|
14 old 1.4 version of git very dumb compared to new version 1.5:: |
|
15 |
|
16 $ sudo apt-get install git-core |
|
17 |
|
18 After install setup some options:: |
|
19 |
|
20 $ git config --global user.name "Oleksandr Gavenko" |
|
21 $ git config --global user.mail "gavenkoa@gmail.com" |
|
22 $ cat ~/.gitconfig |
|
23 [user] |
|
24 name = Oleksandr Gavenko |
|
25 mail = gavenkoa@gmail.com |
|
26 |
|
27 Windows. |
|
28 -------- |
|
29 |
|
30 No official support for Windows OS. |
|
31 |
|
32 Cygwin. |
|
33 ------- |
|
34 |
|
35 $ setup.exe -p git |
|
36 |
|
37 git over proxy. |
|
38 =============== |
|
39 |
|
40 Only http:// protocol support proxy (not git://):: |
|
41 |
|
42 $ export http_proxy="http://username:password@proxy:port/" |
|
43 $ git clone http://github.com/$user/$proj.git $proj |
|
44 |
|
45 You can store proxy settings under repository local config file:: |
|
46 |
|
47 $ git config http.proxy http://$user:$passwd@$ip:$port |
|
48 |
|
49 Start your project. |
|
50 =================== |
|
51 |
|
52 Setup proj space on fs:: |
|
53 |
|
54 $ mkdir proj |
|
55 $ cd proj |
|
56 $ git init |
|
57 Initialized empty Git repository in /home/user/tmp/proj/.git/ |
|
58 $ ls -a |
|
59 . .. .git |
|
60 |
|
61 Add file, make changes, commit all:: |
|
62 |
|
63 $ emacs Makefile |
|
64 ... C-x C-c |
|
65 $ emacs app.c |
|
66 ... C-x C-c |
|
67 $ git add Makefile app.c |
|
68 $ git status |
|
69 # On branch master |
|
70 # |
|
71 # Initial commit |
|
72 # |
|
73 # Changes to be committed: |
|
74 # (use "git rm --cached <file>..." to unstage) |
|
75 # |
|
76 # new file: Makefile |
|
77 # new file: app.c |
|
78 # |
|
79 |
|
80 or just:: |
|
81 |
|
82 $ git add . |
|
83 |
|
84 Commit newlly added file:: |
|
85 |
|
86 $ git commit |
|
87 ... Write message log ... |
|
88 Created initial commit 2169263: My first commit massage. |
|
89 1 files changed, 4 insertions(+), 0 deletions(-) |
|
90 create mode 100644 app.c |
|
91 |
|
92 Undo tracking added file. |
|
93 ========================= |
|
94 |
|
95 You do:: |
|
96 |
|
97 $ git add badfile |
|
98 $ git status |
|
99 # On branch master |
|
100 # Changes to be committed: |
|
101 # (use "git reset HEAD <file>..." to unstage) |
|
102 # |
|
103 # new file: badfile |
|
104 # |
|
105 |
|
106 To stop tracking badfile do:: |
|
107 |
|
108 $ git rm --cached badfile |
|
109 $ git status |
|
110 # On branch master |
|
111 # Untracked files: |
|
112 # (use "git add <file>..." to include in what will be committed) |
|
113 # |
|
114 # file |
|
115 nothing added to commit but untracked files present (use "git add" to track) |
|
116 |
|
117 or:: |
|
118 |
|
119 $ git reset badfile |
|
120 |
|
121 Doing changes. |
|
122 ============== |
|
123 :: |
|
124 |
|
125 $ printf "clean:\n<TAB>rm $(wildcard *.o)\n" >>Makefile |
|
126 $ git diff |
|
127 diff --git a/Makefile b/Makefile |
|
128 index e84f7e9..cd2438a 100644 |
|
129 --- a/Makefile |
|
130 +++ b/Makefile |
|
131 @@ -1,2 +1,5 @@ |
|
132 all: |
|
133 @echo XXX |
|
134 exit 1 |
|
135 + |
|
136 +clean: |
|
137 + rm -f *.o |
|
138 $ git add Makefile |
|
139 $ git commit -m "Added clean target." |
|
140 Created commit 11272b9: Added clean target. |
|
141 1 files changed, 1 insertions(+), 0 deletions(-) |
|
142 create mode 100644 file |
|
143 |
|
144 or just:: |
|
145 |
|
146 $ git commit -a -m "Added clean target." |
|
147 |
|
148 git analog of 'hg incoming'. |
|
149 ============================ |
|
150 |
|
151 git does not directly support such feature. You can emulate it by:: |
|
152 |
|
153 $ git fetch |
|
154 $ git log master..origin/master # or just '..origin/master' |
|
155 |
|
156 By previous commands you grab changes from remote server! You can apply them:: |
|
157 |
|
158 TODO |
|
159 $ git merge |
|
160 |
|
161 git analog of 'hg outgoing'. |
|
162 ============================ |
|
163 |
|
164 git does not directly support such feature. You can emulate it by:: |
|
165 |
|
166 $ git fetch |
|
167 $ git log origin/master..master # or just 'origin/master..' |
|
168 |
|
169 Debug git network operation. |
|
170 ============================ |
|
171 |
|
172 Git uses libcurl for network operation:: |
|
173 |
|
174 $ export GIT_CURL_VERBOSE=1 |
|
175 $ git ... |
|
176 |
|
177 Using git to work with SVN offline. |
|
178 =================================== |
|
179 |
|
180 Prepare SVN and git utilities:: |
|
181 |
|
182 $ sudo apt-get svn git-core git-svn |
|
183 |
|
184 Making SVN repo:: |
|
185 |
|
186 $ cd $HOME/tmp |
|
187 $ svnadmin create svn-repo |
|
188 $ svn co file://$HOME/tmp/svn-repo svn-devel |
|
189 $ cd svn-devel |
|
190 $ mkdir tags trunk branches |
|
191 $ svn add * |
|
192 A branches |
|
193 A tags |
|
194 A trunk |
|
195 $ cd trunk/ |
|
196 $ printf "all:\n echo XXX\n" >Makefile |
|
197 $ printf "int main() {return 0;}" >main.c |
|
198 $ svn add * |
|
199 $ cd .. |
|
200 $ svn st |
|
201 A trunk |
|
202 A trunk/main.c |
|
203 A trunk/Makefile |
|
204 A branches |
|
205 A tags |
|
206 $ svn ci -m init |
|
207 Adding branches |
|
208 Adding tags |
|
209 Adding trunk |
|
210 Adding trunk/Makefile |
|
211 Adding trunk/main.c |
|
212 Transmitting file data .. |
|
213 $ svn cp -m v0.0 file://$HOME/tmp/svn/trunk file://$HOME/tmp/svn/tags/v0.0 |
|
214 $ svn cp -m v0.1 file://$HOME/tmp/svn/trunk file://$HOME/tmp/svn/branches/v0.1 |
|
215 |
|
216 Moving SVN changset to git repo:: |
|
217 |
|
218 $ cd $HOME/tmp |
|
219 $ git svn init file://$HOME/tmp/svn git-repo |
|
220 $ ls -a |
|
221 . .. .git |
|
222 $ git svn fetch |
|
223 A trunk/main.c |
|
224 A trunk/Makefile |
|
225 W: +empty_dir: branches |
|
226 W: +empty_dir: tags |
|
227 r1 = 52ccd9882979dd53ec198dbac108783ec660410f (git-svn) |
|
228 A tags/v0.0/main.c |
|
229 A tags/v0.0/Makefile |
|
230 r2 = 8ec8a772bb6f37ace56b3649066dc84e481ed427 (git-svn) |
|
231 M trunk/Makefile |
|
232 r3 = 2c169ff409ed504dd6a092b1e302beb3fd94871e (git-svn) |
|
233 A branches/v0.1/main.c |
|
234 A branches/v0.1/Makefile |
|
235 r4 = e68d76f4ba6beea4b9059c1884c1f38ce10831a7 (git-svn) |
|
236 M trunk/Makefile |
|
237 r5 = cdde63974454b13ac53f2eeb201aa76c49fd875c (git-svn) |
|
238 Checked out HEAD: |
|
239 file:///home/sasha/tmp/svn r5 |
|
240 |
|
241 or (in old git version):: |
|
242 |
|
243 $ git svn clone file://$HOME/tmp/svn git-repo |
|
244 |
|
245 Making changes in svn:: |
|
246 |
|
247 $ cd $HOME/tmp/svn-devel/trunk |
|
248 $ echo ".PHONY: clean" >>Makefile |
|
249 $ svn ci -m "Added clean to phony." |
|
250 Sending trunk/Makefile |
|
251 Transmitting file data . |
|
252 Committed revision 6. |
|
253 |
|
254 Making committed in git:: |
|
255 |
|
256 $ cd $HOME/tmp/git-repo/trunk |
|
257 $ echo ".PHONY: all" >>Makefile |
|
258 $ echo "int foo(int x) {return x+x;}" >>main.c |
|
259 $ git status |
|
260 # On branch master |
|
261 # Changed but not updated: |
|
262 # (use "git add <file>..." to update what will be committed) |
|
263 # |
|
264 # modified: Makefile |
|
265 # modified: main.c |
|
266 # |
|
267 no changes added to commit (use "git add" and/or "git commit -a") |
|
268 $ git commit -a -m "Bug fixed." |
|
269 Created commit 222d399: Bug fixed. |
|
270 2 files changed, 2 insertions(+), 0 deletions(-) |
|
271 |
|
272 Getting changes from SVN to git:: |
|
273 |
|
274 $ git svn rebase |
|
275 M trunk/Makefile |
|
276 r6 = 8165e9bfb38e9df09a7313d19606ec227629b670 (git-svn) |
|
277 First, rewinding head to replay your work on top of it... |
|
278 Applying Bug fixed. |
|
279 error: patch failed: trunk/Makefile:6 |
|
280 error: trunk/Makefile: patch does not apply |
|
281 Using index info to reconstruct a base tree... |
|
282 Falling back to patching base and 3-way merge... |
|
283 Auto-merged trunk/Makefile |
|
284 CONFLICT (content): Merge conflict in trunk/Makefile |
|
285 Failed to merge in the changes. |
|
286 Patch failed at 0001. |
|
287 |
|
288 When you have resolved this problem run "git rebase --continue". |
|
289 If you would prefer to skip this patch, instead run "git rebase --skip". |
|
290 To restore the original branch and stop rebasing run "git rebase --abort". |
|
291 |
|
292 rebase refs/remotes/git-svn: command returned error: 1 |
|
293 $ git add Makefile |
|
294 $ git rebase --continue |
|
295 Applying Bug fixed. |
|
296 |
|
297 and return all from git to SVN:: |
|
298 |
|
299 $ git svn dcommit |
|
300 Committing to file:///home/sasha/tmp/svn ... |
|
301 M trunk/Makefile |
|
302 M trunk/main.c |
|
303 Committed r7 |
|
304 M trunk/main.c |
|
305 M trunk/Makefile |
|
306 r7 = 68e782c8d06635f2db4dd69b9ca8599f99da22e2 (git-svn) |
|
307 No changes between current HEAD and refs/remotes/git-svn |
|
308 Resetting to the latest refs/remotes/git-svn |
|
309 |
|
310 See what going to SVN repo:: |
|
311 |
|
312 $ cd $HOME/tmp/svn-devel/trunk |
|
313 $ svn diff -r BASE:HEAD |
|
314 Index: Makefile |
|
315 =================================================================== |
|
316 --- Makefile (working copy) |
|
317 +++ Makefile (revision 7) |
|
318 @@ -6,4 +6,4 @@ |
|
319 .o: .c |
|
320 $(CC) $(CFLAGS) -c -o $@ $< |
|
321 |
|
322 -.PHONY: clean |
|
323 +.PHONY: all clean |
|
324 Index: main.c |
|
325 =================================================================== |
|
326 --- main.c (working copy) |
|
327 +++ main.c (revision 7) |
|
328 @@ -2,3 +2,4 @@ |
|
329 { |
|
330 return 0; |
|
331 } |
|
332 +int foo(int x) {return x+x;} |
|
333 $ svn up |
|
334 U Makefile |
|
335 U main.c |
|
336 Updated to revision 7. |
|
337 |
|
338 gitk. |
|
339 ===== |
|
340 |
|
341 gitk - The git repository browser. See gitk(1). |
|
342 |
|
343 Installing:: |
|
344 |
|
345 $ sudo apt-get instal gitk |
|
346 |
|
347 Using:: |
|
348 |
|
349 $ cd /path/to/git-repo |
|
350 $ gitk |
|
351 |