Wednesday, April 7, 2010

Controle de versões Git - Tutorial Resumido dos principais usos do dia dia

**************************************************
SETTING UP THE REPOSITORIES

#############################################
Creating repository (local and master)

# ssh master

If you don't have internal_git folder create

# mkdir -p ~/internal_git/.git && cd ~/internal_git/.git

# git init --bare

To make your repositorie visible the master/git web site

# touch git-daemon-export-ok

Edit the descripition to be viewed in the website

# echo "My project bla" > description

# exit ( or CTRL + D to close connection to master)

Change to your projects folder

# cd

Create and initialize the new project folder

# mkdir && cd && git init

Add your repository in master as the origin remote repository (This step is only required once)

# git remote add origin master:internal_git/.git

Create the files for the project ( .c etc.. )

Add each file you want to have in you Git Rep

# git add .c

or add all the files if you prefer

# git add -A

Commit to your local repositorie

# git commit -m "My first commit message"

Push to the remote repository

# git push origin master

(only in the first time you need to specify the remote origin and the branch master)
Other times you need use just # git push

############################################
Adding other people's repository

# git remote add master:/home//internal_git/.git

###########################################

Getting other people's updates

# git fetch

See the commits

# git log /master

See the differences between yours and other rep

# git diff /master

Get the other updates and merge with you local rep

# git rabase /master

#############################################
Creating your remote repository based on other's repository

# ssh master

# cd ~/internal_git

# git clone --bare /home//internal_git/.git

# exit ( or CTRL + D to close connection to master)

# cd

# git clone master:internal_git/.git


*******************************************************
WORKING AND COMMITING

########################################################

Edit your files

Check the modified lines not commited

# git diff

Add the files you want to commit
--> git add -u (Add files that are modified)
--> git add -A (Add all files)
--> git add (Add only the files you want>

If you want check the modified lines in stagin area (files added to be commited)

# git diff --cached

If you want to cancel add

# git reset HEAD

Use

# git commit -m "message for the commit"

or to use your default editor to edit the message

# git commit

If you want to cancel commit

git reset HEAD^1

If you want to cancel commit reverting your files to previous version

git reset HEAD^1 --hard

If you are satisfied with you changes push to your remote repository on master

git push

#############################################################
Editing commits

If you want to fix the last commit

Add the files modified you want to attach to the last commit

# git add

Use commit amend to commit to the last commit

# git commit --amend

If you want to edit a commit that is not the last one

get the commit ID

# git log

You will see something like this

commit 38135a7503488b7bbc2790f9eec9af1c7006bf33
Author: Thiago Ribeiro Masaki
Date: Fri Mar 12 11:41:39 2010 -0300

Bug fixed in bla

commit d908bebc1e5fd9a6f1eb2aa50d290fdecaafa05e
Author: Thiago Ribeiro Masaki
Date: Fri Mar 12 11:32:40 2010 -0300

ABCD XYZ

commit e03551ae496d4d36def9e54210fcf0ddf348eb85
Author: Thiago Ribeiro Masaki
Date: Fri Mar 12 10:48:38 2010 -0300

Second Commit

commit 271faec25fc2df0907c8e6f80ee89b1627da317e
Author: Thiago Ribeiro Masaki
Date: Fri Mar 12 10:47:19 2010 -0300

Initial Commit

Now use git rebase interactive in a commit previous to the commit you want to edit

for example commit ABCD XYZ get the id for Second Commit

# git rebase -i 271faec25fc2df0907c8e6f80ee89b1627da317e

replace the string pick with edit on the line of the commit you want to edit

Edit the files you want

# git add

# git commit --amend

# git rebase --continue

Update the remote repository using force update (-f)

# git push -f




Ver uma versao de um arquivo

Por exemplo:
git cat-file blob HEAD^^^:some/file.c
git cat-file blob ':some/file.c
ou
git show HEAD^^^:some/file.c
git show ':some/file.c


Removing a branch from your remote repo is a little bit different from removing it locally. It’s all about the colon:
git push :heads/
Example: git push origin :heads/some-branch removes some-branch from the remote repo (apparently git push origin :some-branch works as well).

Get the list of remote branchs

git branch -r

download a remote branch

git checkout -b /

Ex. git checkout -b work origin/work

baixar mudanças

git pull
or
git pull --rebase (the same as) git rebase




git fetch -p
git branch -rd public/master
git revert --no-commit  
grep -s -n --color=always "Trcapp(.*);" $(git ls-files -m)
git rebase -Xtheirs origin/master  (keep my local files as is)
git rebase -Xours origin/master  (keep their remote files as is)

git merge -Xours origin/master  (keep their remote files as is)

No comments:

Blog Archive