-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-pnote-example.txt
150 lines (119 loc) · 4.79 KB
/
git-pnote-example.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# Start and config
; Useful stuff
$ git config --system core.autocrlf false
$ git config --global core.autocrlf false
core.autocrlf false -- Do not convert line-ends (Windows)
color.ui always -- Color interface
merge.tool gvimdiff
clean.requireForce true -- git clean will not work without extras
; Create a new repositry
$ git init
$ git add
$ git commit
; Create a central shared repository
$ git init --bare --shared
; If you already have a repository
; Make en exact copy with tags and branches
$ git push ssh://example.org/git/foo.git '*:*'
; Copy/duplicate/clone
$ git clone ssh://[email protected]/proj.git
# Keywords
master ; default development branch
origin ; default upstream repository
HEAD^^ ; parent of HEAD
HEAD^^ ; grandparent of HEAD
HEAD^4 ; great-great grandparent of HEAD
HEAD~4 ; great-great grandparent of HEAD
HEAD@{4} ; great-great grandparent of HEAD
master@{yesterday}
master@{1 month ago}
# Commit
; Recover/revert lost file
git checkout file
git checkout 268b4206 -- Makefile.in # checkout Makefile.in with blob number
git checkout v1.2.3 -- filename # tag v1.2.3
git checkout stable -- filename # stable branch
git checkout origin/master -- filename # upstream master
git checkout HEAD -- filename # the version from the most recent commit
git checkout HEAD^ -- filename # the version before the most recent commit
; Have not commited and want to revert everything
$ git reset --hard
; take the last commit back (keep working tree)
$ git reset --soft HEAD^
$ git checkout myfile.txt
$ git checkout -- path/file.txt
$ git commit --amend ; Re-enter last commit
; Forgot something in your last commit?
$ git reset --soft HEAD^
$ git add forgot.txt these.txt
$ git commit
# Work with a remote Git
git clone /home/alice bob ; Clone a copy of Alice
git pull /home/bob master ; fetch & merge Bob's master branch into HEAD
git remote add bob /home/bob ; Make "bob" a shortcut
git pull bob ; Merge Bob with a shortcut
git pull ; The "svn update" considering last path
git push ; Push changes to origin
git fetch /home/bob master ; Inspect Bob's changes before merge/pull
git log -p HEAD..FETCH_HEAD
git push origin tagname ; Push tagname to remote location (even deletions)
# Merge conflicts
git diff
git diff --base $file
git diff --ours $file
git diff --theirs $file
git add conflict_file.txt ; Solve conflict
git rebase --continue
git reset --hard ; Discard conflict
git rebase --skip
git checkout --ours index.html
git checkout --theirs _layouts/default.html
; Merge three repositories A, B, C
mkdir combined && cd combined
git init
git fetch ../A master:A
git fetch ../B master:B
git fetch ../C master:C
git checkout A
git merge B
git merge C
# Recepies
; Stash use
# You must switch to another branch but cannot commit now
git stash list
git stash save "your message here"
gitk stash
# now switch, work and some time later go back to your working branch
git stash pop
# also you might like to research...
git diff stash@{0}
git stash apply stash@{1}
git stash drop stash@{1}
; Daily work with branch/rebase*/merge
Use rebase to keep your branch updated with the stuff people is doing.
The idea is to keep working in something as similar as possible to the trunk
and have as few differences as possible for an easy final merge
# clone the remote repo
$ git co -b my_new_feature
# ..work and commit some stuff
$ git rebase master
# ..work and commit some stuff
$ git rebase master
# ..finish the feature
$ git co master
$ git merge my_new_feature
; Github
# Download and install Git
$ git config --global user.name "Francisco Garcia"
$ git config --global user.email [email protected]
# Add your public key <url:http://github.com/account#keys>
; If clone empty
$ git clone [email protected]:FGarcia/repository.git
; If using existing one
$ git remote add origin [email protected]:FGarcia/Katas.git
$ git push origin master
; if you have no key yet ...
$ ssh-keygen -C "[email protected]" -t rsa
On Windows make sure .ssh folder is in your user folder at
"Documments and Settings"
vim:ft=pnote