author | Oleksandr Gavenko <gavenkoa@gmail.com> |
Sat, 10 Feb 2018 01:36:16 +0200 | |
changeset 2229 | 1a0b6597e594 |
parent 2214 | f7b3d90697ab |
child 2232 | ac7f6d8bea28 |
permissions | -rw-r--r-- |
1002 | 1 |
.. -*- coding: utf-8; -*- |
2 |
||
3 |
====== |
|
4 |
Git. |
|
5 |
====== |
|
1032
4decc3e00bb6
Fix coding and contents.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1002
diff
changeset
|
6 |
.. contents:: |
1905
fba288d59662
Include only local subsections into TOC. This prevent duplication of
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1815
diff
changeset
|
7 |
:local: |
1002 | 8 |
|
2101 | 9 |
Setting up git |
10 |
============== |
|
1002 | 11 |
|
2101 | 12 |
Debian:: |
1002 | 13 |
|
2081
0d9703b4a428
Remove outdated data. Fix formatting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1932
diff
changeset
|
14 |
$ sudo apt-get install git |
1002 | 15 |
|
2101 | 16 |
Cygwin:: |
17 |
||
18 |
$ setup.exe -p git |
|
19 |
$ apt-cyg install git |
|
20 |
||
21 |
After install set up some options:: |
|
1002 | 22 |
|
23 |
$ git config --global user.name "Oleksandr Gavenko" |
|
24 |
$ git config --global user.mail "gavenkoa@gmail.com" |
|
2101 | 25 |
|
26 |
After that you should have:: |
|
27 |
||
1002 | 28 |
$ cat ~/.gitconfig |
29 |
[user] |
|
2101 | 30 |
name = Oleksandr Gavenko |
31 |
mail = gavenkoa@gmail.com |
|
1002 | 32 |
|
33 |
git over proxy. |
|
34 |
=============== |
|
35 |
||
36 |
Only http:// protocol support proxy (not git://):: |
|
37 |
||
38 |
$ export http_proxy="http://username:password@proxy:port/" |
|
39 |
$ git clone http://github.com/$user/$proj.git $proj |
|
40 |
||
41 |
You can store proxy settings under repository local config file:: |
|
42 |
||
43 |
$ git config http.proxy http://$user:$passwd@$ip:$port |
|
44 |
||
2081
0d9703b4a428
Remove outdated data. Fix formatting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1932
diff
changeset
|
45 |
Start project with git |
0d9703b4a428
Remove outdated data. Fix formatting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1932
diff
changeset
|
46 |
====================== |
1002 | 47 |
|
48 |
Setup proj space on fs:: |
|
49 |
||
50 |
$ mkdir proj |
|
51 |
$ cd proj |
|
52 |
$ git init |
|
53 |
Initialized empty Git repository in /home/user/tmp/proj/.git/ |
|
54 |
$ ls -a |
|
55 |
. .. .git |
|
56 |
||
57 |
Add file, make changes, commit all:: |
|
58 |
||
59 |
$ emacs Makefile |
|
60 |
... C-x C-c |
|
61 |
$ emacs app.c |
|
62 |
... C-x C-c |
|
63 |
$ git add Makefile app.c |
|
64 |
$ git status |
|
65 |
# On branch master |
|
66 |
# |
|
67 |
# Initial commit |
|
68 |
# |
|
69 |
# Changes to be committed: |
|
70 |
# (use "git rm --cached <file>..." to unstage) |
|
71 |
# |
|
72 |
# new file: Makefile |
|
73 |
# new file: app.c |
|
74 |
# |
|
75 |
||
76 |
or just:: |
|
77 |
||
78 |
$ git add . |
|
79 |
||
80 |
Commit newlly added file:: |
|
81 |
||
82 |
$ git commit |
|
83 |
... Write message log ... |
|
84 |
Created initial commit 2169263: My first commit massage. |
|
85 |
1 files changed, 4 insertions(+), 0 deletions(-) |
|
86 |
create mode 100644 app.c |
|
87 |
||
2209 | 88 |
Show difference |
89 |
=============== |
|
90 |
||
91 |
Show difference between index/stage and working tree:: |
|
92 |
||
93 |
$ git diff |
|
94 |
||
95 |
Show difference between ``HEAD`` and index (what is going to be commited):: |
|
96 |
||
97 |
$ git diff --cached |
|
98 |
$ git diff --staged |
|
99 |
||
100 |
.. note:: ``--cached`` and ``--staged`` are synonyms. |
|
101 |
||
102 |
Show difference beetween ``HEAD`` and working tree (what is commited after ``git commit -a``):: |
|
103 |
||
104 |
$ git diff HEAD |
|
105 |
$ git diff HEAD -- $path |
|
106 |
||
107 |
Show difference in changeset:: |
|
108 |
||
109 |
$ git show $hash |
|
110 |
||
111 |
Show difference between revisions:: |
|
112 |
||
113 |
$ git diff $rev1..$rev2 |
|
114 |
$ git diff ORIG_HEAD..HEAD |
|
115 |
||
116 |
https://stackoverflow.com/questions/3293607/difference-between-git-head-and-the-current-project-state |
|
117 |
Difference between git HEAD and the current project state? |
|
118 |
||
1002 | 119 |
Undo tracking added file. |
120 |
========================= |
|
121 |
||
122 |
You do:: |
|
123 |
||
124 |
$ git add badfile |
|
125 |
$ git status |
|
126 |
# On branch master |
|
127 |
# Changes to be committed: |
|
128 |
# (use "git reset HEAD <file>..." to unstage) |
|
129 |
# |
|
130 |
# new file: badfile |
|
131 |
# |
|
132 |
||
133 |
To stop tracking badfile do:: |
|
134 |
||
135 |
$ git rm --cached badfile |
|
136 |
$ git status |
|
137 |
# On branch master |
|
138 |
# Untracked files: |
|
139 |
# (use "git add <file>..." to include in what will be committed) |
|
140 |
# |
|
141 |
# file |
|
142 |
nothing added to commit but untracked files present (use "git add" to track) |
|
143 |
||
144 |
or:: |
|
145 |
||
146 |
$ git reset badfile |
|
147 |
||
2082
7f6ce6b18a0c
Remove unnecessary details.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2081
diff
changeset
|
148 |
Committing changes |
7f6ce6b18a0c
Remove unnecessary details.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2081
diff
changeset
|
149 |
================== |
1002 | 150 |
|
2082
7f6ce6b18a0c
Remove unnecessary details.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2081
diff
changeset
|
151 |
Individual file:: |
7f6ce6b18a0c
Remove unnecessary details.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2081
diff
changeset
|
152 |
|
7f6ce6b18a0c
Remove unnecessary details.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2081
diff
changeset
|
153 |
$ $EDITOR Makefile |
7f6ce6b18a0c
Remove unnecessary details.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2081
diff
changeset
|
154 |
$ git add Makefile |
2152
a48ba30d5b20
Fixed example for done changes review.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2126
diff
changeset
|
155 |
$ git diff --cached |
2082
7f6ce6b18a0c
Remove unnecessary details.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2081
diff
changeset
|
156 |
$ git commit -m "..." |
1002 | 157 |
|
2082
7f6ce6b18a0c
Remove unnecessary details.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2081
diff
changeset
|
158 |
Commit all changed and previously manages files:: |
1002 | 159 |
|
2082
7f6ce6b18a0c
Remove unnecessary details.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2081
diff
changeset
|
160 |
$ git commit -a -m "...." |
1002 | 161 |
|
2084 | 162 |
Managing branches |
163 |
================= |
|
164 |
||
165 |
Print current branch:: |
|
166 |
||
167 |
$ git branch |
|
168 |
||
169 |
List all known branches:: |
|
170 |
||
171 |
$ git branch -a |
|
172 |
||
173 |
List all known remote branches:: |
|
174 |
||
175 |
$ git branch -r |
|
176 |
||
177 |
List all remote branches (from all remotes):: |
|
178 |
||
179 |
$ git ls-remote |
|
2190 | 180 |
$ git ls-remote origin |
181 |
||
182 |
List registered remotes:: |
|
183 |
||
184 |
$ git remote show |
|
2084 | 185 |
|
186 |
List remote branches from ``$REMOTE`` remote:: |
|
187 |
||
188 |
$ git ls-remote --heads $REMOTE |
|
189 |
$ git remote show $REMOTE |
|
190 |
||
2190 | 191 |
Special case of above is ``origin`` remote, which is default remote:: |
192 |
||
193 |
$ git remote show origin |
|
194 |
$ git ls-remote --heads origin |
|
195 |
||
2084 | 196 |
.. note:: |
197 |
||
198 |
Look to ``[remote "..."]`` in ``~/.git/config`` to find out names of possible |
|
199 |
remotes. Alternatively get list from:: |
|
200 |
||
201 |
$ git remote show |
|
202 |
||
2190 | 203 |
Getting branches pointers from default (``origin``) remote (without merging |
204 |
tracking branch):: |
|
2084 | 205 |
|
206 |
$ git fetch |
|
207 |
||
208 |
Getting branches pointers from ``$REMOTE`` remote:: |
|
209 |
||
210 |
$ git fetch $REMOTE |
|
211 |
||
2190 | 212 |
To get updated with default remote changes:: |
213 |
||
214 |
$ git pull |
|
215 |
||
216 |
or specify concrete remote:: |
|
217 |
||
218 |
$ git pull $REMOTE |
|
219 |
$ git pull origin |
|
220 |
||
2214
f7b3d90697ab
Delete remote branch remotely.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2211
diff
changeset
|
221 |
Delete local branch:: |
f7b3d90697ab
Delete remote branch remotely.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2211
diff
changeset
|
222 |
|
f7b3d90697ab
Delete remote branch remotely.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2211
diff
changeset
|
223 |
$ git branch -d $NAME |
f7b3d90697ab
Delete remote branch remotely.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2211
diff
changeset
|
224 |
|
f7b3d90697ab
Delete remote branch remotely.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2211
diff
changeset
|
225 |
Delete remote branch remotely:: |
f7b3d90697ab
Delete remote branch remotely.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2211
diff
changeset
|
226 |
|
f7b3d90697ab
Delete remote branch remotely.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2211
diff
changeset
|
227 |
$ git push --delete $REMOTE $BRANCH_NAME |
f7b3d90697ab
Delete remote branch remotely.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2211
diff
changeset
|
228 |
$ git push -d $REMOTE $BRANCH_NAME |
f7b3d90697ab
Delete remote branch remotely.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2211
diff
changeset
|
229 |
$ git push -d origin $BRANCH_NAME |
f7b3d90697ab
Delete remote branch remotely.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2211
diff
changeset
|
230 |
|
2190 | 231 |
To locally remove pointers to deleted remotely branches:: |
232 |
||
233 |
$ git remote update --prune |
|
234 |
$ git remote update --prune origin |
|
235 |
||
2084 | 236 |
.. note:: |
237 |
||
238 |
Only curtain branches fetched by default:: |
|
239 |
||
240 |
[remote "origin"] |
|
2123
f98c2b2e6c07
View unpublished git commits- added links.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2122
diff
changeset
|
241 |
url = ... |
f98c2b2e6c07
View unpublished git commits- added links.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2122
diff
changeset
|
242 |
fetch = +refs/heads/*:refs/remotes/origin/* |
2084 | 243 |
|
244 |
Edit ``fetch`` value to change defaults. |
|
245 |
||
2171
2ded7f1cf6c0
Move branch pointer to arbitrary hash.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2153
diff
changeset
|
246 |
Move branch pointer to arbitrary hash:: |
2ded7f1cf6c0
Move branch pointer to arbitrary hash.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2153
diff
changeset
|
247 |
|
2ded7f1cf6c0
Move branch pointer to arbitrary hash.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2153
diff
changeset
|
248 |
$ git branch -f $NAME $HASH |
2ded7f1cf6c0
Move branch pointer to arbitrary hash.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2153
diff
changeset
|
249 |
|
2085
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
250 |
git analog of 'hg incoming' |
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
251 |
=========================== |
1002 | 252 |
|
253 |
git does not directly support such feature. You can emulate it by:: |
|
254 |
||
255 |
$ git fetch |
|
256 |
$ git log master..origin/master # or just '..origin/master' |
|
257 |
||
2085
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
258 |
By previous commands you grab changes from remote server! You can apply them by |
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
259 |
``pull`` or ``merge`` or ``rebase`` command:: |
1002 | 260 |
|
2085
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
261 |
$ git pull |
1002 | 262 |
$ git merge |
2085
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
263 |
TODO |
1002 | 264 |
|
2085
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
265 |
To detect if remote repository have new changes:: |
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
266 |
|
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
267 |
$ git ls-remote |
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
268 |
$ git ls-remote $upstream |
652aca73fc06
Detect if remote repository have new changes.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2084
diff
changeset
|
269 |
|
2126 | 270 |
View git commits |
271 |
================ |
|
272 |
||
273 |
Review specific commit with:: |
|
274 |
||
275 |
$ git show $REV |
|
276 |
$ git diff $REV^ $REV |
|
277 |
||
278 |
Review difference between commits:: |
|
279 |
||
280 |
$ git $REV1 $REV2 |
|
2153
e88e36e73ebc
Review difference between commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2152
diff
changeset
|
281 |
$ git $REV1..$REV2 |
e88e36e73ebc
Review difference between commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2152
diff
changeset
|
282 |
$ git $REV1..$REV2 -- $DIR_OR_FILE |
2126 | 283 |
|
284 |
Review history with diffs:: |
|
285 |
||
286 |
$ git log -p |
|
287 |
$ git log -p $FROM_REV |
|
288 |
||
2122
24fbab64cf91
View unpublished git commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2116
diff
changeset
|
289 |
View unpublished git commits / analog of git 'hg outgoing' |
24fbab64cf91
View unpublished git commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2116
diff
changeset
|
290 |
========================================================== |
24fbab64cf91
View unpublished git commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2116
diff
changeset
|
291 |
|
24fbab64cf91
View unpublished git commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2116
diff
changeset
|
292 |
``git`` does not directly support such feature. Recently ``hg`` start tracking |
24fbab64cf91
View unpublished git commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2116
diff
changeset
|
293 |
changes that pushed to any other repositories (called as ``public`` versus |
24fbab64cf91
View unpublished git commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2116
diff
changeset
|
294 |
``draft`` which is not yet published anywhere). You can emulate it by:: |
1002 | 295 |
|
2122
24fbab64cf91
View unpublished git commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2116
diff
changeset
|
296 |
$ git fetch origin |
24fbab64cf91
View unpublished git commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2116
diff
changeset
|
297 |
$ git log origin/master..master |
24fbab64cf91
View unpublished git commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2116
diff
changeset
|
298 |
$ git log origin/master.. |
24fbab64cf91
View unpublished git commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2116
diff
changeset
|
299 |
$ git log origin/master..HEAD |
24fbab64cf91
View unpublished git commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2116
diff
changeset
|
300 |
$ git log @{u}.. |
1002 | 301 |
|
2122
24fbab64cf91
View unpublished git commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2116
diff
changeset
|
302 |
$ git diff origin/master.. |
24fbab64cf91
View unpublished git commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2116
diff
changeset
|
303 |
|
24fbab64cf91
View unpublished git commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2116
diff
changeset
|
304 |
Verbose syntax:: |
24fbab64cf91
View unpublished git commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2116
diff
changeset
|
305 |
|
24fbab64cf91
View unpublished git commits.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2116
diff
changeset
|
306 |
$ git log --branches --not --remotes |
1002 | 307 |
|
2123
f98c2b2e6c07
View unpublished git commits- added links.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2122
diff
changeset
|
308 |
http://stackoverflow.com/questions/2016901/viewing-unpushed-git-commits |
f98c2b2e6c07
View unpublished git commits- added links.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2122
diff
changeset
|
309 |
Viewing unpushed Git commits. |
f98c2b2e6c07
View unpublished git commits- added links.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2122
diff
changeset
|
310 |
http://stackoverflow.com/questions/3636914/how-can-i-see-what-i-am-about-to-push-with-git |
f98c2b2e6c07
View unpublished git commits- added links.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2122
diff
changeset
|
311 |
How can I see what I am about to push with git? |
f98c2b2e6c07
View unpublished git commits- added links.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2122
diff
changeset
|
312 |
|
2102
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
313 |
git analog of 'hg glog' |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
314 |
======================= |
1650
a48c3c61d0f9
git analog of 'hg glog'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1641
diff
changeset
|
315 |
:: |
a48c3c61d0f9
git analog of 'hg glog'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1641
diff
changeset
|
316 |
|
a48c3c61d0f9
git analog of 'hg glog'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1641
diff
changeset
|
317 |
$ git log --all --graph |
2102
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
318 |
$ git log --all --graph --oneline |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
319 |
$ git log --all --graph --oneline --decorate |
1650
a48c3c61d0f9
git analog of 'hg glog'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1641
diff
changeset
|
320 |
|
a48c3c61d0f9
git analog of 'hg glog'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1641
diff
changeset
|
321 |
Add alias:: |
a48c3c61d0f9
git analog of 'hg glog'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1641
diff
changeset
|
322 |
|
a48c3c61d0f9
git analog of 'hg glog'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1641
diff
changeset
|
323 |
[alias] |
a48c3c61d0f9
git analog of 'hg glog'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1641
diff
changeset
|
324 |
glog = log --all --graph |
a48c3c61d0f9
git analog of 'hg glog'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1641
diff
changeset
|
325 |
|
2116 | 326 |
Git analog of 'hg rollback' |
327 |
=========================== |
|
1651
c77807176b36
Git analog of 'hg rollback'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1650
diff
changeset
|
328 |
|
c77807176b36
Git analog of 'hg rollback'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1650
diff
changeset
|
329 |
To edit commit message of last commit:: |
c77807176b36
Git analog of 'hg rollback'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1650
diff
changeset
|
330 |
|
c77807176b36
Git analog of 'hg rollback'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1650
diff
changeset
|
331 |
$ git commit --amend -m "$MSG" |
c77807176b36
Git analog of 'hg rollback'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1650
diff
changeset
|
332 |
|
2116 | 333 |
To integrate changes into last commit (``-a`` to avoid antecedent ``git add ...``, |
334 |
``--no-edit`` if you don't like to change commit message, otherwise external |
|
335 |
editor is opened):: |
|
336 |
||
337 |
$ git commit -a --amend --no-edit |
|
338 |
||
1651
c77807176b36
Git analog of 'hg rollback'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1650
diff
changeset
|
339 |
To edit messages of old commits starting from ``$REV``:: |
c77807176b36
Git analog of 'hg rollback'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1650
diff
changeset
|
340 |
|
c77807176b36
Git analog of 'hg rollback'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1650
diff
changeset
|
341 |
$ git rebase -i $REV |
c77807176b36
Git analog of 'hg rollback'
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1650
diff
changeset
|
342 |
|
2124 | 343 |
To undo latest commit:: |
344 |
||
345 |
$ git reset HEAD~1 |
|
346 |
||
2102
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
347 |
Git analog of 'hg root' |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
348 |
======================= |
1771
b2d4be61da16
Git analog of 'hg root'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1714
diff
changeset
|
349 |
:: |
b2d4be61da16
Git analog of 'hg root'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1714
diff
changeset
|
350 |
|
b2d4be61da16
Git analog of 'hg root'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1714
diff
changeset
|
351 |
$ git rev-parse --show-toplevel |
b2d4be61da16
Git analog of 'hg root'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1714
diff
changeset
|
352 |
|
2102
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
353 |
Making local branch tracking remote |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
354 |
=================================== |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
355 |
:: |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
356 |
|
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
357 |
$ git branch -u upstream/foo |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
358 |
$ git branch -u upstream/foo foo |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
359 |
|
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
360 |
$ git branch --set-upstream-to=upstream/foo |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
361 |
$ git branch --set-upstream-to=upstream/foo foo |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
362 |
|
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
363 |
Showing what and how local branches are tracked:: |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
364 |
|
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
365 |
$ git branch -vv |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
366 |
$ cat .git/gitconfig |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
367 |
|
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
368 |
Showing what remote branches tracked:: |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
369 |
|
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
370 |
$ git remote show $remote |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
371 |
|
2115
0263a79eeb3b
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2102
diff
changeset
|
372 |
Undo mistaken rebase |
0263a79eeb3b
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2102
diff
changeset
|
373 |
==================== |
0263a79eeb3b
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2102
diff
changeset
|
374 |
|
0263a79eeb3b
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2102
diff
changeset
|
375 |
If there are no any ``reset``, ``rebase`` or ``merge`` afterwards the easiest |
0263a79eeb3b
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2102
diff
changeset
|
376 |
way to recode to pre-rebase state is one of:: |
0263a79eeb3b
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2102
diff
changeset
|
377 |
|
0263a79eeb3b
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2102
diff
changeset
|
378 |
$ git rebase --abort |
0263a79eeb3b
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2102
diff
changeset
|
379 |
$ git reset --hard ORIG_HEAD |
0263a79eeb3b
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2102
diff
changeset
|
380 |
|
2172
850d2d84e4c8
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2171
diff
changeset
|
381 |
Otherwise look to:: |
850d2d84e4c8
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2171
diff
changeset
|
382 |
|
850d2d84e4c8
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2171
diff
changeset
|
383 |
$ git reflog |
850d2d84e4c8
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2171
diff
changeset
|
384 |
|
850d2d84e4c8
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2171
diff
changeset
|
385 |
and reset to necessary head:: |
850d2d84e4c8
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2171
diff
changeset
|
386 |
|
850d2d84e4c8
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2171
diff
changeset
|
387 |
$ git reset --hard "HEAD@{...}" |
850d2d84e4c8
Undo mistaken rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2171
diff
changeset
|
388 |
|
2173
69aed373ceb9
Undoing git rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2172
diff
changeset
|
389 |
https://stackoverflow.com/questions/134882/undoing-a-git-rebase |
69aed373ceb9
Undoing git rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2172
diff
changeset
|
390 |
Undoing git rebase. |
69aed373ceb9
Undoing git rebase.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2172
diff
changeset
|
391 |
|
2179 | 392 |
Undo reset --hard |
393 |
================= |
|
394 |
||
395 |
``git reset --hard`` is destructive command without backup data. |
|
396 |
||
397 |
You may find your previously added data in Git garbage:: |
|
398 |
||
399 |
$ git fsck --lost-found |
|
400 |
||
401 |
look to files inside ``.git/lost-found`` directory. |
|
402 |
||
403 |
Reviewing ``git reflog`` also may help. |
|
404 |
||
405 |
* https://stackoverflow.com/questions/5788037/recover-from-git-reset-hard |
|
406 |
* https://stackoverflow.com/questions/14251194/how-to-recover-after-i-execute-git-reset-hard-head |
|
407 |
||
2175 | 408 |
Git bisect |
409 |
========== |
|
410 |
||
2176 | 411 |
``bad`` changes should be later in graph history then ``good`` ones. To use |
412 |
alternative names:: |
|
413 |
||
414 |
$ git start --term-old=... --term-new=... |
|
2175 | 415 |
|
416 |
Start bisecting with:: |
|
417 |
||
418 |
$ git bisect start |
|
419 |
||
420 |
Mark good and bad revisions:: |
|
421 |
||
422 |
$ git co vBAD |
|
423 |
$ make test |
|
424 |
$ git bisect bad |
|
425 |
||
426 |
$ git co vGOOD |
|
427 |
$ make test |
|
428 |
$ git bisect good |
|
429 |
||
430 |
||
431 |
If build/test failed to complete use:: |
|
432 |
||
433 |
$ git bisect skip |
|
434 |
||
435 |
To restore mistakenly marked revisions:: |
|
436 |
||
437 |
$ git bisect log >$LOG |
|
438 |
$ git bisect reset |
|
439 |
$ $EDITOR $LOG |
|
440 |
$ git bisect replay $LOG |
|
441 |
||
2211 | 442 |
Import patch |
443 |
============ |
|
444 |
||
445 |
Check patch summary:: |
|
446 |
||
447 |
git apply --stat my.patch |
|
448 |
||
449 |
Detect possible errors during patch application:: |
|
450 |
||
451 |
git apply --check my.patch |
|
452 |
||
453 |
Apply patch to working tree without commit:: |
|
454 |
||
455 |
git apply my.patch |
|
456 |
||
457 |
Commit patch:: |
|
458 |
||
459 |
git am my.patch |
|
460 |
||
461 |
Commit patch by signing you as reviewer:: |
|
462 |
||
463 |
git am --signoff my.patch |
|
464 |
||
2102
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
465 |
Debug git network operation |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
466 |
=========================== |
1002 | 467 |
|
468 |
Git uses libcurl for network operation:: |
|
469 |
||
470 |
$ export GIT_CURL_VERBOSE=1 |
|
471 |
$ git ... |
|
472 |
||
1076
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
473 |
Push new repo to remote. |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
474 |
======================== |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
475 |
:: |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
476 |
|
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
477 |
$ mkdir $REPO |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
478 |
$ cd $REPO |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
479 |
$ git init |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
480 |
$ git add . |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
481 |
$ git commit -m "Initial commit" |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
482 |
$ git remote add origin https://$USER:$PASS@$HOST/$REPO |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
483 |
$ git push -u origin master |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
484 |
|
1641
04e215a475e0
Show heads in branch.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1334
diff
changeset
|
485 |
Show heads in branch. |
04e215a475e0
Show heads in branch.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1334
diff
changeset
|
486 |
===================== |
04e215a475e0
Show heads in branch.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1334
diff
changeset
|
487 |
:: |
04e215a475e0
Show heads in branch.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1334
diff
changeset
|
488 |
|
04e215a475e0
Show heads in branch.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1334
diff
changeset
|
489 |
$ git show-ref --heads -s |
04e215a475e0
Show heads in branch.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1334
diff
changeset
|
490 |
|
1932
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
491 |
Search string in file |
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
492 |
===================== |
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
493 |
|
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
494 |
To search string in all or specific files or working copy:: |
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
495 |
|
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
496 |
$ git grep $PATT |
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
497 |
$ git grep -i $PATT -- '*.[ch]' |
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
498 |
|
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
499 |
To search in all history:: |
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
500 |
|
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
501 |
$ git log -S$PATT |
2195
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
502 |
$ git log --pickaxe-regex=$PATT |
1932
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
503 |
$ git log -G$PATT |
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
504 |
$ git grep -i PATT $(git rev-list --all) -- '*.[ch]' |
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
505 |
|
2195
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
506 |
.. note:: |
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
507 |
|
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
508 |
``-S`` search occurences in diff chunks, while ``-G`` detects changes in match count. |
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
509 |
|
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
510 |
https://git-scm.com/book/en/v2/Git-Tools-Searching |
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
511 |
Git Tools - Searching. |
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
512 |
https://stackoverflow.com/questions/1337320/how-to-grep-git-commit-diffs-or-contents-for-a-certain-word |
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
513 |
How to grep Git commit diffs or contents for a certain word? |
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
514 |
https://stackoverflow.com/questions/4468361/search-all-of-git-history-for-a-string |
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
515 |
Search all of Git history for a string? |
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
516 |
https://stackoverflow.com/questions/2928584/how-to-grep-search-committed-code-in-the-git-history |
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
517 |
How to grep (search) committed code in the git history? |
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
518 |
|
1089
2c23dfe7517e
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1076
diff
changeset
|
519 |
Find most recent tag for revision. |
2c23dfe7517e
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1076
diff
changeset
|
520 |
================================== |
2c23dfe7517e
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1076
diff
changeset
|
521 |
:: |
2c23dfe7517e
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1076
diff
changeset
|
522 |
|
2c23dfe7517e
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1076
diff
changeset
|
523 |
$ git describe $REV |
2c23dfe7517e
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1076
diff
changeset
|
524 |
|
1815
49fb4309d4d0
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1771
diff
changeset
|
525 |
Many projects set tags on branches rather then mainline (for example JS/CSS |
49fb4309d4d0
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1771
diff
changeset
|
526 |
projects perform build and commit binary/minified files, which unnecessary for |
49fb4309d4d0
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1771
diff
changeset
|
527 |
mainline history). In this case review simplifiied history by:: |
49fb4309d4d0
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1771
diff
changeset
|
528 |
|
49fb4309d4d0
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1771
diff
changeset
|
529 |
$ git log --graph --all --decorate --oneline --simplify-by-decoration |
49fb4309d4d0
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1771
diff
changeset
|
530 |
|
1714
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
531 |
List tags with dates. |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
532 |
===================== |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
533 |
:: |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
534 |
|
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
535 |
$ git log --tags --simplify-by-decoration --pretty="format:%ci %d" |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
536 |
|
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
537 |
Update to date. |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
538 |
=============== |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
539 |
:: |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
540 |
|
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
541 |
$ git checkout 'master@{1979-02-26}' |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
542 |
$ git checkout 'master@{1979-02-26 18:30:00}' |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
543 |
|
1002 | 544 |
Using git to work with SVN offline. |
545 |
=================================== |
|
546 |
||
547 |
Prepare SVN and git utilities:: |
|
548 |
||
549 |
$ sudo apt-get svn git-core git-svn |
|
550 |
||
551 |
Making SVN repo:: |
|
552 |
||
553 |
$ cd $HOME/tmp |
|
554 |
$ svnadmin create svn-repo |
|
555 |
$ svn co file://$HOME/tmp/svn-repo svn-devel |
|
556 |
$ cd svn-devel |
|
557 |
$ mkdir tags trunk branches |
|
558 |
$ svn add * |
|
559 |
A branches |
|
560 |
A tags |
|
561 |
A trunk |
|
562 |
$ cd trunk/ |
|
563 |
$ printf "all:\n echo XXX\n" >Makefile |
|
564 |
$ printf "int main() {return 0;}" >main.c |
|
565 |
$ svn add * |
|
566 |
$ cd .. |
|
567 |
$ svn st |
|
568 |
A trunk |
|
569 |
A trunk/main.c |
|
570 |
A trunk/Makefile |
|
571 |
A branches |
|
572 |
A tags |
|
573 |
$ svn ci -m init |
|
574 |
Adding branches |
|
575 |
Adding tags |
|
576 |
Adding trunk |
|
577 |
Adding trunk/Makefile |
|
578 |
Adding trunk/main.c |
|
579 |
Transmitting file data .. |
|
580 |
$ svn cp -m v0.0 file://$HOME/tmp/svn/trunk file://$HOME/tmp/svn/tags/v0.0 |
|
581 |
$ svn cp -m v0.1 file://$HOME/tmp/svn/trunk file://$HOME/tmp/svn/branches/v0.1 |
|
582 |
||
583 |
Moving SVN changset to git repo:: |
|
584 |
||
585 |
$ cd $HOME/tmp |
|
586 |
$ git svn init file://$HOME/tmp/svn git-repo |
|
587 |
$ ls -a |
|
588 |
. .. .git |
|
589 |
$ git svn fetch |
|
590 |
A trunk/main.c |
|
591 |
A trunk/Makefile |
|
592 |
W: +empty_dir: branches |
|
593 |
W: +empty_dir: tags |
|
594 |
r1 = 52ccd9882979dd53ec198dbac108783ec660410f (git-svn) |
|
595 |
A tags/v0.0/main.c |
|
596 |
A tags/v0.0/Makefile |
|
597 |
r2 = 8ec8a772bb6f37ace56b3649066dc84e481ed427 (git-svn) |
|
598 |
M trunk/Makefile |
|
599 |
r3 = 2c169ff409ed504dd6a092b1e302beb3fd94871e (git-svn) |
|
600 |
A branches/v0.1/main.c |
|
601 |
A branches/v0.1/Makefile |
|
602 |
r4 = e68d76f4ba6beea4b9059c1884c1f38ce10831a7 (git-svn) |
|
603 |
M trunk/Makefile |
|
604 |
r5 = cdde63974454b13ac53f2eeb201aa76c49fd875c (git-svn) |
|
605 |
Checked out HEAD: |
|
606 |
file:///home/sasha/tmp/svn r5 |
|
607 |
||
608 |
or (in old git version):: |
|
609 |
||
610 |
$ git svn clone file://$HOME/tmp/svn git-repo |
|
611 |
||
612 |
Making changes in svn:: |
|
613 |
||
614 |
$ cd $HOME/tmp/svn-devel/trunk |
|
615 |
$ echo ".PHONY: clean" >>Makefile |
|
616 |
$ svn ci -m "Added clean to phony." |
|
617 |
Sending trunk/Makefile |
|
618 |
Transmitting file data . |
|
619 |
Committed revision 6. |
|
620 |
||
621 |
Making committed in git:: |
|
622 |
||
623 |
$ cd $HOME/tmp/git-repo/trunk |
|
624 |
$ echo ".PHONY: all" >>Makefile |
|
625 |
$ echo "int foo(int x) {return x+x;}" >>main.c |
|
626 |
$ git status |
|
627 |
# On branch master |
|
628 |
# Changed but not updated: |
|
629 |
# (use "git add <file>..." to update what will be committed) |
|
630 |
# |
|
631 |
# modified: Makefile |
|
632 |
# modified: main.c |
|
633 |
# |
|
634 |
no changes added to commit (use "git add" and/or "git commit -a") |
|
635 |
$ git commit -a -m "Bug fixed." |
|
636 |
Created commit 222d399: Bug fixed. |
|
637 |
2 files changed, 2 insertions(+), 0 deletions(-) |
|
638 |
||
639 |
Getting changes from SVN to git:: |
|
640 |
||
641 |
$ git svn rebase |
|
642 |
M trunk/Makefile |
|
643 |
r6 = 8165e9bfb38e9df09a7313d19606ec227629b670 (git-svn) |
|
644 |
First, rewinding head to replay your work on top of it... |
|
645 |
Applying Bug fixed. |
|
646 |
error: patch failed: trunk/Makefile:6 |
|
647 |
error: trunk/Makefile: patch does not apply |
|
648 |
Using index info to reconstruct a base tree... |
|
649 |
Falling back to patching base and 3-way merge... |
|
650 |
Auto-merged trunk/Makefile |
|
651 |
CONFLICT (content): Merge conflict in trunk/Makefile |
|
652 |
Failed to merge in the changes. |
|
653 |
Patch failed at 0001. |
|
654 |
||
655 |
When you have resolved this problem run "git rebase --continue". |
|
656 |
If you would prefer to skip this patch, instead run "git rebase --skip". |
|
657 |
To restore the original branch and stop rebasing run "git rebase --abort". |
|
658 |
||
659 |
rebase refs/remotes/git-svn: command returned error: 1 |
|
660 |
$ git add Makefile |
|
661 |
$ git rebase --continue |
|
662 |
Applying Bug fixed. |
|
663 |
||
664 |
and return all from git to SVN:: |
|
665 |
||
666 |
$ git svn dcommit |
|
667 |
Committing to file:///home/sasha/tmp/svn ... |
|
668 |
M trunk/Makefile |
|
669 |
M trunk/main.c |
|
670 |
Committed r7 |
|
671 |
M trunk/main.c |
|
672 |
M trunk/Makefile |
|
673 |
r7 = 68e782c8d06635f2db4dd69b9ca8599f99da22e2 (git-svn) |
|
674 |
No changes between current HEAD and refs/remotes/git-svn |
|
675 |
Resetting to the latest refs/remotes/git-svn |
|
676 |
||
677 |
See what going to SVN repo:: |
|
678 |
||
679 |
$ cd $HOME/tmp/svn-devel/trunk |
|
680 |
$ svn diff -r BASE:HEAD |
|
681 |
Index: Makefile |
|
682 |
=================================================================== |
|
683 |
--- Makefile (working copy) |
|
684 |
+++ Makefile (revision 7) |
|
685 |
@@ -6,4 +6,4 @@ |
|
686 |
.o: .c |
|
687 |
$(CC) $(CFLAGS) -c -o $@ $< |
|
688 |
||
689 |
-.PHONY: clean |
|
690 |
+.PHONY: all clean |
|
691 |
Index: main.c |
|
692 |
=================================================================== |
|
693 |
--- main.c (working copy) |
|
694 |
+++ main.c (revision 7) |
|
695 |
@@ -2,3 +2,4 @@ |
|
696 |
{ |
|
697 |
return 0; |
|
698 |
} |
|
699 |
+int foo(int x) {return x+x;} |
|
700 |
$ svn up |
|
701 |
U Makefile |
|
702 |
U main.c |
|
703 |
Updated to revision 7. |
|
704 |
||
705 |
gitk. |
|
706 |
===== |
|
707 |
||
708 |
gitk - The git repository browser. See gitk(1). |
|
709 |
||
710 |
Installing:: |
|
711 |
||
712 |
$ sudo apt-get instal gitk |
|
713 |
||
714 |
Using:: |
|
715 |
||
716 |
$ cd /path/to/git-repo |
|
717 |
$ gitk |
|
718 |