author | Oleksandr Gavenko <gavenkoa@gmail.com> |
Mon, 03 Dec 2018 16:56:36 +0200 | |
changeset 2288 | b30c7905636d |
parent 2262 | bb7e7ae562c2 |
child 2292 | cd4554e0150e |
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 |
|
2253 | 225 |
Delete remote branch:: |
2214
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 |
||
2232
ac7f6d8bea28
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2214
diff
changeset
|
408 |
Undo mistaken push |
ac7f6d8bea28
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2214
diff
changeset
|
409 |
================== |
ac7f6d8bea28
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2214
diff
changeset
|
410 |
:: |
ac7f6d8bea28
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2214
diff
changeset
|
411 |
|
ac7f6d8bea28
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2214
diff
changeset
|
412 |
$ git reset HEAD^ |
ac7f6d8bea28
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2214
diff
changeset
|
413 |
$ git push --force |
ac7f6d8bea28
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2214
diff
changeset
|
414 |
|
ac7f6d8bea28
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2214
diff
changeset
|
415 |
Alternative commands may look like:: |
ac7f6d8bea28
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2214
diff
changeset
|
416 |
|
ac7f6d8bea28
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2214
diff
changeset
|
417 |
$ git reset --hard $HASH |
ac7f6d8bea28
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2214
diff
changeset
|
418 |
$ git push -u origin master --force |
ac7f6d8bea28
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2214
diff
changeset
|
419 |
|
2233
d0c386e6f039
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2232
diff
changeset
|
420 |
You can delete remote branch with syntax of appended colon before branch name:: |
d0c386e6f039
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2232
diff
changeset
|
421 |
|
d0c386e6f039
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2232
diff
changeset
|
422 |
$ git reset HEAD^ |
d0c386e6f039
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2232
diff
changeset
|
423 |
$ git push origin :$NAME |
d0c386e6f039
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2232
diff
changeset
|
424 |
$ git push origin $NAME |
d0c386e6f039
Undo mistaken push.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2232
diff
changeset
|
425 |
|
2175 | 426 |
Git bisect |
427 |
========== |
|
428 |
||
2176 | 429 |
``bad`` changes should be later in graph history then ``good`` ones. To use |
430 |
alternative names:: |
|
431 |
||
432 |
$ git start --term-old=... --term-new=... |
|
2175 | 433 |
|
434 |
Start bisecting with:: |
|
435 |
||
436 |
$ git bisect start |
|
437 |
||
438 |
Mark good and bad revisions:: |
|
439 |
||
440 |
$ git co vBAD |
|
441 |
$ make test |
|
442 |
$ git bisect bad |
|
443 |
||
444 |
$ git co vGOOD |
|
445 |
$ make test |
|
446 |
$ git bisect good |
|
447 |
||
448 |
||
449 |
If build/test failed to complete use:: |
|
450 |
||
451 |
$ git bisect skip |
|
452 |
||
453 |
To restore mistakenly marked revisions:: |
|
454 |
||
455 |
$ git bisect log >$LOG |
|
456 |
$ git bisect reset |
|
457 |
$ $EDITOR $LOG |
|
458 |
$ git bisect replay $LOG |
|
459 |
||
2211 | 460 |
Import patch |
461 |
============ |
|
462 |
||
463 |
Check patch summary:: |
|
464 |
||
465 |
git apply --stat my.patch |
|
466 |
||
467 |
Detect possible errors during patch application:: |
|
468 |
||
469 |
git apply --check my.patch |
|
470 |
||
471 |
Apply patch to working tree without commit:: |
|
472 |
||
473 |
git apply my.patch |
|
474 |
||
475 |
Commit patch:: |
|
476 |
||
477 |
git am my.patch |
|
478 |
||
479 |
Commit patch by signing you as reviewer:: |
|
480 |
||
481 |
git am --signoff my.patch |
|
482 |
||
2102
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
483 |
Debug git network operation |
ce5d8887b874
Making local branch tracking remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2101
diff
changeset
|
484 |
=========================== |
1002 | 485 |
|
486 |
Git uses libcurl for network operation:: |
|
487 |
||
488 |
$ export GIT_CURL_VERBOSE=1 |
|
489 |
$ git ... |
|
490 |
||
1076
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
491 |
Push new repo to remote. |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
492 |
======================== |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
493 |
:: |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
494 |
|
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
495 |
$ mkdir $REPO |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
496 |
$ cd $REPO |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
497 |
$ git init |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
498 |
$ git add . |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
499 |
$ git commit -m "Initial commit" |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
500 |
$ git remote add origin https://$USER:$PASS@$HOST/$REPO |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
501 |
$ git push -u origin master |
9b2eb3c96d84
Push new repo to remote.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1032
diff
changeset
|
502 |
|
1641
04e215a475e0
Show heads in branch.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1334
diff
changeset
|
503 |
Show heads in branch. |
04e215a475e0
Show heads in branch.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1334
diff
changeset
|
504 |
===================== |
04e215a475e0
Show heads in branch.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1334
diff
changeset
|
505 |
:: |
04e215a475e0
Show heads in branch.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1334
diff
changeset
|
506 |
|
04e215a475e0
Show heads in branch.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1334
diff
changeset
|
507 |
$ git show-ref --heads -s |
04e215a475e0
Show heads in branch.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1334
diff
changeset
|
508 |
|
1932
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
509 |
Search string in file |
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
510 |
===================== |
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
511 |
|
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
512 |
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
|
513 |
|
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
514 |
$ git grep $PATT |
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
515 |
$ git grep -i $PATT -- '*.[ch]' |
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
516 |
|
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
517 |
To search in all history:: |
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
518 |
|
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
519 |
$ git log -S$PATT |
2195
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
520 |
$ git log --pickaxe-regex=$PATT |
1932
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
521 |
$ git log -G$PATT |
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
522 |
$ git grep -i PATT $(git rev-list --all) -- '*.[ch]' |
6b987b040e18
Search string in file
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1912
diff
changeset
|
523 |
|
2195
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
524 |
.. note:: |
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
525 |
|
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
526 |
``-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
|
527 |
|
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
528 |
https://git-scm.com/book/en/v2/Git-Tools-Searching |
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
529 |
Git Tools - Searching. |
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
530 |
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
|
531 |
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
|
532 |
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
|
533 |
Search all of Git history for a string? |
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
534 |
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
|
535 |
How to grep (search) committed code in the git history? |
3556ec0e48be
Search string in file.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2190
diff
changeset
|
536 |
|
1089
2c23dfe7517e
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1076
diff
changeset
|
537 |
Find most recent tag for revision. |
2c23dfe7517e
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1076
diff
changeset
|
538 |
================================== |
2c23dfe7517e
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1076
diff
changeset
|
539 |
:: |
2c23dfe7517e
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1076
diff
changeset
|
540 |
|
2c23dfe7517e
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1076
diff
changeset
|
541 |
$ git describe $REV |
2c23dfe7517e
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1076
diff
changeset
|
542 |
|
1815
49fb4309d4d0
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1771
diff
changeset
|
543 |
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
|
544 |
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
|
545 |
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
|
546 |
|
49fb4309d4d0
Find most recent tag for revision.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1771
diff
changeset
|
547 |
$ 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
|
548 |
|
1714
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
549 |
List tags with dates. |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
550 |
===================== |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
551 |
:: |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
552 |
|
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
553 |
$ git log --tags --simplify-by-decoration --pretty="format:%ci %d" |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
554 |
|
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
555 |
Update to date. |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
556 |
=============== |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
557 |
:: |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
558 |
|
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
559 |
$ git checkout 'master@{1979-02-26}' |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
560 |
$ git checkout 'master@{1979-02-26 18:30:00}' |
eed8cfffa44e
List tags with dates.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1651
diff
changeset
|
561 |
|
1002 | 562 |
Using git to work with SVN offline. |
563 |
=================================== |
|
564 |
||
565 |
Prepare SVN and git utilities:: |
|
566 |
||
567 |
$ sudo apt-get svn git-core git-svn |
|
568 |
||
569 |
Making SVN repo:: |
|
570 |
||
2251 | 571 |
$ cd $HOME/tmp |
572 |
$ svnadmin create svn-repo |
|
573 |
$ svn co file://$HOME/tmp/svn-repo svn-devel |
|
574 |
||
575 |
$ cd svn-devel |
|
576 |
$ mkdir tags trunk branches |
|
577 |
||
578 |
$ svn add * |
|
1002 | 579 |
A branches |
580 |
A tags |
|
581 |
A trunk |
|
2251 | 582 |
|
583 |
$ cd trunk/ |
|
584 |
$ printf "all:\n echo XXX\n" >Makefile |
|
585 |
$ printf "int main() {return 0;}" >main.c |
|
586 |
||
587 |
$ svn add * |
|
588 |
||
589 |
$ cd .. |
|
590 |
||
591 |
$ svn st |
|
1002 | 592 |
A trunk |
593 |
A trunk/main.c |
|
594 |
A trunk/Makefile |
|
595 |
A branches |
|
596 |
A tags |
|
2251 | 597 |
|
598 |
$ svn ci -m init |
|
1002 | 599 |
Adding branches |
600 |
Adding tags |
|
601 |
Adding trunk |
|
602 |
Adding trunk/Makefile |
|
603 |
Adding trunk/main.c |
|
604 |
Transmitting file data .. |
|
605 |
$ svn cp -m v0.0 file://$HOME/tmp/svn/trunk file://$HOME/tmp/svn/tags/v0.0 |
|
606 |
$ svn cp -m v0.1 file://$HOME/tmp/svn/trunk file://$HOME/tmp/svn/branches/v0.1 |
|
607 |
||
608 |
Moving SVN changset to git repo:: |
|
609 |
||
2251 | 610 |
$ cd $HOME/tmp |
611 |
$ git svn init file://$HOME/tmp/svn git-repo |
|
612 |
$ ls -a |
|
1002 | 613 |
. .. .git |
2251 | 614 |
|
615 |
$ git svn fetch |
|
1002 | 616 |
A trunk/main.c |
617 |
A trunk/Makefile |
|
618 |
W: +empty_dir: branches |
|
619 |
W: +empty_dir: tags |
|
620 |
r1 = 52ccd9882979dd53ec198dbac108783ec660410f (git-svn) |
|
621 |
A tags/v0.0/main.c |
|
622 |
A tags/v0.0/Makefile |
|
623 |
r2 = 8ec8a772bb6f37ace56b3649066dc84e481ed427 (git-svn) |
|
624 |
M trunk/Makefile |
|
625 |
r3 = 2c169ff409ed504dd6a092b1e302beb3fd94871e (git-svn) |
|
626 |
A branches/v0.1/main.c |
|
627 |
A branches/v0.1/Makefile |
|
628 |
r4 = e68d76f4ba6beea4b9059c1884c1f38ce10831a7 (git-svn) |
|
629 |
M trunk/Makefile |
|
630 |
r5 = cdde63974454b13ac53f2eeb201aa76c49fd875c (git-svn) |
|
631 |
Checked out HEAD: |
|
632 |
file:///home/sasha/tmp/svn r5 |
|
633 |
||
634 |
or (in old git version):: |
|
635 |
||
636 |
$ git svn clone file://$HOME/tmp/svn git-repo |
|
637 |
||
638 |
Making changes in svn:: |
|
639 |
||
2251 | 640 |
$ cd $HOME/tmp/svn-devel/trunk |
641 |
$ echo ".PHONY: clean" >>Makefile |
|
642 |
$ svn ci -m "Added clean to phony." |
|
1002 | 643 |
Sending trunk/Makefile |
644 |
Transmitting file data . |
|
645 |
Committed revision 6. |
|
646 |
||
647 |
Making committed in git:: |
|
648 |
||
2251 | 649 |
$ cd $HOME/tmp/git-repo/trunk |
650 |
$ echo ".PHONY: all" >>Makefile |
|
651 |
$ echo "int foo(int x) {return x+x;}" >>main.c |
|
652 |
$ git status |
|
1002 | 653 |
# On branch master |
654 |
# Changed but not updated: |
|
655 |
# (use "git add <file>..." to update what will be committed) |
|
656 |
# |
|
657 |
# modified: Makefile |
|
658 |
# modified: main.c |
|
659 |
# |
|
660 |
no changes added to commit (use "git add" and/or "git commit -a") |
|
661 |
$ git commit -a -m "Bug fixed." |
|
662 |
Created commit 222d399: Bug fixed. |
|
663 |
2 files changed, 2 insertions(+), 0 deletions(-) |
|
664 |
||
665 |
Getting changes from SVN to git:: |
|
666 |
||
2251 | 667 |
$ git svn rebase |
668 |
M trunk/Makefile |
|
1002 | 669 |
r6 = 8165e9bfb38e9df09a7313d19606ec227629b670 (git-svn) |
670 |
First, rewinding head to replay your work on top of it... |
|
671 |
Applying Bug fixed. |
|
672 |
error: patch failed: trunk/Makefile:6 |
|
673 |
error: trunk/Makefile: patch does not apply |
|
674 |
Using index info to reconstruct a base tree... |
|
675 |
Falling back to patching base and 3-way merge... |
|
676 |
Auto-merged trunk/Makefile |
|
677 |
CONFLICT (content): Merge conflict in trunk/Makefile |
|
678 |
Failed to merge in the changes. |
|
679 |
Patch failed at 0001. |
|
680 |
||
681 |
When you have resolved this problem run "git rebase --continue". |
|
682 |
If you would prefer to skip this patch, instead run "git rebase --skip". |
|
683 |
To restore the original branch and stop rebasing run "git rebase --abort". |
|
684 |
||
685 |
rebase refs/remotes/git-svn: command returned error: 1 |
|
686 |
$ git add Makefile |
|
687 |
$ git rebase --continue |
|
688 |
Applying Bug fixed. |
|
689 |
||
690 |
and return all from git to SVN:: |
|
691 |
||
2251 | 692 |
$ git svn dcommit |
1002 | 693 |
Committing to file:///home/sasha/tmp/svn ... |
694 |
M trunk/Makefile |
|
695 |
M trunk/main.c |
|
696 |
Committed r7 |
|
697 |
M trunk/main.c |
|
698 |
M trunk/Makefile |
|
699 |
r7 = 68e782c8d06635f2db4dd69b9ca8599f99da22e2 (git-svn) |
|
700 |
No changes between current HEAD and refs/remotes/git-svn |
|
701 |
Resetting to the latest refs/remotes/git-svn |
|
702 |
||
703 |
See what going to SVN repo:: |
|
704 |
||
2251 | 705 |
$ cd $HOME/tmp/svn-devel/trunk |
706 |
$ svn diff -r BASE:HEAD |
|
1002 | 707 |
Index: Makefile |
708 |
=================================================================== |
|
709 |
--- Makefile (working copy) |
|
710 |
+++ Makefile (revision 7) |
|
711 |
@@ -6,4 +6,4 @@ |
|
712 |
.o: .c |
|
713 |
$(CC) $(CFLAGS) -c -o $@ $< |
|
714 |
||
715 |
-.PHONY: clean |
|
716 |
+.PHONY: all clean |
|
717 |
Index: main.c |
|
718 |
=================================================================== |
|
719 |
--- main.c (working copy) |
|
720 |
+++ main.c (revision 7) |
|
721 |
@@ -2,3 +2,4 @@ |
|
722 |
{ |
|
723 |
return 0; |
|
724 |
} |
|
725 |
+int foo(int x) {return x+x;} |
|
726 |
$ svn up |
|
727 |
U Makefile |
|
728 |
U main.c |
|
729 |
Updated to revision 7. |
|
730 |
||
2262
bb7e7ae562c2
Get latest changes from SVN and update Git repo state.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2253
diff
changeset
|
731 |
Get latest changes from SVN and update Git repo state:: |
bb7e7ae562c2
Get latest changes from SVN and update Git repo state.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2253
diff
changeset
|
732 |
|
bb7e7ae562c2
Get latest changes from SVN and update Git repo state.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2253
diff
changeset
|
733 |
$ git svn fetch |
bb7e7ae562c2
Get latest changes from SVN and update Git repo state.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2253
diff
changeset
|
734 |
$ git svn rebase |
bb7e7ae562c2
Get latest changes from SVN and update Git repo state.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
2253
diff
changeset
|
735 |
|
1002 | 736 |
gitk. |
737 |
===== |
|
738 |
||
739 |
gitk - The git repository browser. See gitk(1). |
|
740 |
||
741 |
Installing:: |
|
742 |
||
743 |
$ sudo apt-get instal gitk |
|
744 |
||
745 |
Using:: |
|
746 |
||
747 |
$ cd /path/to/git-repo |
|
748 |
$ gitk |
|
749 |