Anda di halaman 1dari 27

GIT

for rasdaman
P.CAMPALANI L-SIS Developers' Aid Internal Document
GIT 2
GIT

CREATOR
Linus Torvalds (hence it works, and fast)

WHAT
Source Code ana!e"ent (SC) s#ste"

WHE$
%& A'ril ())*

The development started on the 3


rd
of April of the same year.
+t is o'en,source (-.L) and distri/uted0 no need to have a
central re'o (e1!1 C2S, Su/version) where to co""it chan!es
each workin! director# is a full#,fled!ed re'ositor#
with own histor# and full ca'a/ilities1
the stupid content tracker
GIT 3
Some Basics (I)

SHA,% hash values


Ever# co""it has a snapshot, /ound with (and
referred to /#) its checksu" inte!rit#1 E3a"'le0
454a(a67(&(%c)86%7dee(d*ea&*/%%868)*6/%c

9suall# (:5&; of the cases) a co""it will look like0


commit <some-hash-value>
Author: Dimitar Misev <misev@rasdaman.com>
Date: <some-date>
<some-message>
Usually the first 6-7 chars of the hash are enough to identify a commit.
GIT 4
Some Basics (II)

The 4 states

O<+=+E<
A file has /een "odified, nothin! "ore1

STA-E< git add


A "odified file has /een "arked so that it will /e
included in the ne3t co""it sna'shot1
A file (staging area, or index) in the -+T 'ro>ect
director# .git/ kee's track of the sta!ed chan!es1

CO+TTE< git commit


Chan!es to a file are included in the new current
co""it (HEA<)1
Some Basics (III)

Re"otes git remote


The# are re"ote

versions of #our re'ositor#


(decentralization) and are useful either when
colla/oratin! with others, or as si"'le /acku's1
When a 'ro>ect is cloned fro" a re"ote re'ositor#,
this latter one is called origin /# default1
Over network or nternet! somewhere else from your local machine.
> git remote -verbose
origin git://kahlua.eecs.jacobs-university.de/rasdaman.git (fetch)
origin git://kahlua.eecs.jacobs-university.de/rasdaman.git (push)

Some Basics (IV)

?ranches git branch / git checkout


Ever# co""it has ) or "ore parents0 ) for the first
co""it, % for a nor"al co""it, $ 'arents for
co""its resulted fro" a "er!e of /ranches1
The default /ranch is called master1
=or instance, co""it H is the "er!in! of G and G'1
E--- F--- G topicB
/
| E'--- F'--- G' topicA
|/ \
A-->B---C---D---E---F---G---H---I master
GIT 7
Get started

Clone the rasdaman 'ro>ect0

Set #our contact infor"ation0

Set #our favorite editor, that is vim 0


> git clone git://kahlua.eecs.jacobs-university.de/rasdaman.git
> cd ./rasdaman
> git config user.name "Rob Zombie"
> git config user.email rob@jacobs-university.de
> echo export GIT_EDITOR=vim >> ~/.bashrc
> source ~/.bashrc
GIT 8
Create a remote copy (I)

=irstl#, initiali@e a e"'t# re'ositor# in the re"ote


server0
This re'o is created as /are0 it does not 'rovide a workin! tree,
as #ou are not "eant to 'h#sicall# work thereA it >ust records
co""its, /ranches, etc1 when #ou 'ush to it, and !ives #ou
the latest versions when #ou clone or 'ull fro" it1
<user>@<host>:~$ git init --bare --shared rasdaman.git
<user>@<host>:~$ ls -a rasdaman.git/
. .. branches config description HEAD hooks info objects refs
REASO$0 /acku'sA /rid!e /etween re'ositories on
different hosts (e1!1 #our la'to' and office)1
GIT 9
Create a remote copy (II)

Add the re"ote location to "# local re'ositor#0


> git remote add backup ssh://<user>@<host>:/path/to/rasdaman.git
> git remote
backup
origin # ---> kahlua
> git checkout topic1 # need to move to the branch.
> git push backup topic1
> git config --get remote.backup.url

E3a"'le0 'ush /ranch topic1 to the re"ote co'#0

=or!ot 9RL backup re"oteB


GIT 10
Quick patch (I)

?efore "akin! chan!es to the 'ro>ect, alwa#s ali!n


#our co'# to the latest chan!es in origin 0
> cd ./rasdaman # or wherever in the directory tree of rasdaman.
> git fetch # read remote index (from 'origin' by default).
> git log -1 --pretty=format:'%h %an | %ar | %s' origin
d9fe1ac Alireza Rezaei Mahdiraji | 3 weeks ago | Collecting []
> git reset -hard d9fe1ac
HEAD is now at d9fe1ac Collecting []
synchronize your HEAD
Runnin! directl# git pull "i!ht end u' in a new local
co""it that "er!es originCs HEA< with so"e chan!es in
#our local co'# #ou "i!ht have for!otten1
11
Quick patch (II)

After "akin! the chan!es to the file(s), sta!e the"0


> vim -p PetascopeInterface.java ConfigManager.java
[...]
> git add PetascopeInterface.java ConfigManager.java
> git status
On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: PetascopeInterface.java
# modified: ConfigManager.java
[...]
modify and stage
Alwa#s "ind the advices and su!!estions
in the out'ut of the !it co""ands1
GIT 12
Quick patch (III)

$ow >ust co""it and for"at the 'atch0

Then su/"it it to the 'atch "ana!er of rasdaman0


http://rasdaman.eecs.aco!s-universit".de/trac/rasdaman/patchmanager
> git commit -m My brief description of the patch.
[testing 670418d] My brief description of the patch.
2 files changed, 11 insertions(+), 3 deletions(-)
> git format-patch HEAD~1 # = with changes of the last 1 commit
0001-My-brief-description-of-the-patch.patch
?efore co""ittin!, take care that #ou didnCt lose ali!n"ent with origin
/ecause of so"e acce'ted 'atch in the "eanti"e that "i!ht clash0
> git stash # get back to a clean working directory
> git pull # apply the new remote changes to your repo
> git stash pop # restore your stashed changes: now commit them.
commit and format
Quick patch (IV)

+n the unluck# case that #our chan!es are in confli ct with


new 'ulled co""its, #ou need to "anuall# solve the" and
then #ou can drop the stash fro" the stack0
> git stash pop
Auto-merging PetascopeInterface.java
CONFLICT (content): Merge conflict in PetascopeInterface.java
> vim PetascopeInterface.java
<<<<<<< Updated upstream String key = null;
String key=null, val=null; String val = null;
=======
String key;
String val;
>>>>>>> Stashed changes
> git stash list
stash@{0}: WIP on master: d9fe1ac Collecting []
> git stash drop stash@{0} # now you are aligned: add and commit!

solve conflicts
GIT 14
Days-long patch (I)

Stashin!D'o''in! could still work, /ut #ou "i!ht want to


/acku' #our work on a re"ote /ranch to let #ou 'ull fro" it
afterwards fro" an other "achine (e1!1 #our ho"e la'to' for the
weekend )1

.ro'osed workflow0 git push / git rebase


%1 <ail# co""its E /acku', until #ou finish the taskA
(1 -rou' #our co""its into a sin!le patch,co""itA
41 ove #our 'atch,co""it on to' of all the new co""its
that were a''lied to origin in the "eanti"eA
81 =or"at the 'atch and u'load itA
be redundant
GIT 15
Days-long patch (II)
E---F---G topic : daily commits on my
/ new branch
A-->B---C---D master
E' topic : group commits E, F and G
/ (job finished)
A-->B---C---D---H---I master : new applied patches
E' topic : move my changes
/ on top of I
A-->B---C---D---H---I master

branch-view
Days-long patch (III)
Create a se'arate new /ranch for #our work0
<ail# work0 "odif# the filesA when #ouCre finished then
sta!e, co""it and /acku' #our chan!es0
> vim -p <whatever>
[...]
> git status
> git add that-file.cc that-other-file.hh last-file.sh.in
> git commit -m What I did today
> git push backup newtopic # to my 'backup' remote

command-view: setup
> git checkout -b mytopic # create new branch and move there
> git branch
master
* mytopic # mind the star

Days-long patch (IV)


Fo/ finished1 -rou' #our chan!es into one co""it with
"eanin!ful "essa!e for the 'atch0
command-view: multiplex
> git rebase --interactive HEAD~2 # simple case: 2 commits
pick 222855e commit 12oct pick 222855e commit 12oct
pick 5a20f20 commit 13oct squash 5a20f20 commit 13oct

+ s#uashed ("er!ed) the second co""it into the 'revious


one1 After :wq,in!, #ou will /e asked to ada't the "essa!es0
# This is a combination of 2 commits. # This is a combination of 2 commits.
# The first commit's message is: # The first commit's message is:
commit 12oct Fixed this stuff (ticket 666).
# This is the 2nd commit message:
commit 13oct
[...] Successfully rebased and updated refs/heads/testing.

:wq

GIT 18
Days-long patch (V)
The uniGue co""it of the 'atch "i!ht pro!a!l" need to /e
"oved on to' of originCs HEA<0
command-view: move on top
> git fetch origin # update origin's history.
> git rebase origin # move current branch on top of origin.

+n case of confl icts, re/asin! will /e sus'ended Ctil #ou fi3


the"1 Once done, continue re/asin! (then for"at 'atch) 0
[...] CONFLICT (content): Merge conflict in WcsUtil.java
Failed to merge in the changes.
> vim WcsUtil.java # fix conflict(s) [ ]
> git add WcsUtil.java # mark it as resolved.
> git rebase --continue # proceed 'til end (or next conflict )
GIT 19
arnings (I)

$ever sta!e intentionall# untracked files (e1!1 akefiles)

To check whether a file is tracked /# !it, #ou can run0


untracked files
> git ls-files update_petascopedb.sh.in -error-unmatch
update_petascopedb.sh.in # tracked
> git ls-files update_petascopedb.sh -error-unmatch
error: pathspec 'update_petascopedb.sh' did not match any file(s)
known to git. # untracked

To unsta!e an untracked file accidentall# added to the


inde30
> git add update_petascopedb.sh # ops
> git reset HEAD update_petascopedb.sh # unstage it
GIT 20
arnings (II)

Re"e"/er to avoid si"'le rm when deletin! files fro"


the 'ro>ect, the# need to /e sta!ed as well0
deleting files
> rm NoMoreNeededClass.java # or directly:
> git rm NoMoreNeededClass.java
rm applications/petascope/src/main/java/petascope/NoMoreNeededClass.java

To restore a file accidentall" deleted0


> git checkout - DidNotWantToDropThis.java # from HEAD by default
$OTE0 onl# staged chan!es H if chan!es were ever done on the
deleted file H will /e restored, otherwise tr# this and start 'ra#in!1
arnings (III)

9'on "er!esDre/asin!, this "i!ht ha''en0


> git branch
master
* topic
> git push backup topic
To <user>@<host>:/path/to/rasdaman.git
! [rejected] topic -> topic (non-fast-forward)
This is /ecause /are re'ositories (backup) onl# acce't
linear histor# chan!es on a /ranch0 A,I?,IC and so on1
Fust delete the /ranch on the re"ote and re,'ush a!ain0
non-fast-forward updates
<user>@<host>:~/rasdaman.git$ git branch -D topic
Deleted branch topic (was ea6873f).
> git push backup topic
GIT 22
Q!" (I)

Which chan!es have JI$ done until nowB git diff


> git diff # view unstaged changes
> git diff -cached # view changes staged for commit (git-added)

Which chan!es did co""it 3966eefB git show


> git show 3966eef # see all changes in the code
Hint: '/\+\+\+' then 'n'/'N' to move through the output
> git show 3966eef --stat # see only a summary of changes

commit 3966eef2077a5adbf649c35430f753791b7967d2
Author: Somebody Someone <foo@jacobs-university.de>
Date: Fri Oct 26 13:15:52 2012 +0200
Description of this commit.
./util/WcsUtil.java | 39 ++++++++++++++------
1 file changed, 26 insertions(+), 13 deletions(-)
The same " -stat" option can #e used with git-log.
GIT 23
Q!" (II)

Which co""its chan!ed the file

this%ile.x"z B git log


> git log --pretty=format:'%h %an | %ar | %s' /path/to/thisFile.xyz
57b100b Piero Campalani | 3 months ago | Reasoning why I did this.
d2afcfd Dimitar Misev | 4 months ago | Hyper-brief reason.
Then use !it show to ins'ect those chan!es0
> git show d2afcfd /path/to/thisFile.xyz

Which co""its introduced or re"oved an instance


of thisString B
The same holds for changes on any file inside a specified directory.
> git log --pretty=format:'%h %an | %ar | %s' -S'thisString'
GIT 24
Q!" (III)

How to re"ove this%ile.x"z fro" "# last (un'atchedK

)
co""it B
> git show -stat | grep thisFile.xyz # show HEAD, by default
./path/to/thisFile.xyz | 2 +-
> git reset HEAD~1 /path/to/thisFile.xyz
> git commit --amend -v
(You have now the chance also to change the message of the commit)
> git show -stat | grep thisFile.xyz
> # --> the file is not in the commit anymore

How was this%ile.x"z at a 'recedent co""itB


Otherwise $ust let it there and push a new patch that fi%es the error.
> git show 8f27e6:/path/to/thisFile.xyz # explicit checksum.
> git show v8.2:/path/to/thisFile.xyz # tag label.
Q!" (IV)

What are the ta!s of rasdaman B


> git tag -list | tr '\n' '|' # labels only
v8.0|v8.1|v8.2|v8.2.1|v8.3|v8.3.1|
> git show-ref -tags # labels and correspondent commits

How can + test so"ethin! on the "ain re'o without a new


clone while + a" develo'in! a 'atchB
> git fetch
> git checkout -b temporary origin/HEAD
> git checkout master
> git pull
+n case #ou are workin! on #our
master /ranch, and need to
create a new one for &ahlua1
+n case #ou are workin! on a
se'arate /ranch, leavin! master
as #our local co'# of &ahlua1
$OTE0 /efore a checkout, #ou "i!ht often need to either
stash or commit #our chan!es to avoid losin! data1
GIT 26
#inal suggestions

A!ain, kee' alwa#s a /acku' of #our work (this su!!estion


is "ore !enerall# valid for life)0
> git push my-backup-server my-current-branch # or good old:
> tar czvf rasdaman-29oct.tar.gz rasdaman/

9se colored !it out'ut0


> git config --global color.ui auto # also: always and never

9se /ranches0 locall# co"'are /ehavior of kahluaA do real


merging of chan!es (and no overwriting)0
> git checkout -b new-branch # start new branch from HEAD.
> git rebase master # move on top of new patches.
$e%erences

Official We/ Site


http://git-scm.com/

-+T /ook
http://git-scm.com/!oo&

LinusC talk at -oo!le (())7)


http://www."outu!e.com/watch'v()*pn+,-Ao&.

Wiki 'a!e L kahlua /0outdated1


http://&ahlua.eecs.aco!s-universit".de/trac/wi&i/wi&i/2it3epositories

$ice tutorial
http://schacon.githu!.com/git/gittutorial.html

$ice co""ands reference


http://gitre4.org/

> man git-*

Anda mungkin juga menyukai