Postanowiłem przedstawić kilka użytecznych komend systemu kontroli wersji GIT
ustawienia:
git config –list
git config –global user.name “dupa jas”
git config –global user.email fdsf@das.pl
git config –global core.editor vim
git config –global merge.tool diff
git help command
man git-command
git status
git init #create git structure in .git directory
podstawowe komendy:
git add . #dodaje wszystkie pliki bieżącego katalogu do śledzenia
git rm file #usuwanie pliku
git mv file1 file2 #przeniesienie
git commit -a m “comment” #commit zmian z pominięciem warstwy stage
git commit -v #pokazuje zmiany do commit-a
git commit –amend
branchowanie:
git branch -a #lista branchy, bieżący oznaczony gwiazdką
git branch [branch_name] #tworzy nowy branch
git checkout [branch_name] #przechodzi do branch-a
git checkout -b [branch_name] #tworzy i przechodzi do branch-a
git checkout — [file]
git branch [branch_name] [hash|tag] #nowy branch utworzony z hash-a lub tag-a
git branch -d [branch_name] #usuwa branch
git branch –merged
git branch –no-merged
logi:
git log
git log -1 #pokazuje ostatni commit
git log -p -2 #pokazuje różnice między dwoma ostatnimi commit-ami
git log –pretty=oneline|short|medium|full|fuller|email
git log –pretty=format:”%h – %an, %ar : %s”
git log –pretty=format:”%h %s” –graph
git log –merged #tylko merged commit
różnice:
git diff #różnice między warstwą tzw. “working directory” i “staged”
git diff –staged #różnice między warstwą “stage” i ostatnim commit-em
git diff –cached
tagowanie:
git tag #pokazuje tag-i
git tag -a v1 -m ‘comment’ #dodanie taga
git show v1
git tag -a v1.1 [hash] #tagowanie starych commit-ów
pozostałe:
git merge [branch_name] #do bieżącego branch-a merguje zmiany z branch-a [branch_name]
git ls-files –stage #pokazuje pliki z warstwy “stage”
git hash-object [file] #tworzy SHA1 hash dla pliku [file]
git mergetool #wybór nażędzia do mergowania
.gitignore #lista ignorowanych plików
praca zdalna:
inicjalizacja projektu na serwerze bez “working directory”:
mkdir project-01.git
cd project-01.git
git –bare init
inicjalizacja projektu w lokalnym katalogu:
git init
git add .
git commit -m “initialize project”
wysłanie na serwer zdalny:
git remote add origin [user]@[server]:/[path on server to git project dir]
git push origin master
git remote -v #sprawdzenie zdalnego serwera
git remote add [alias] user@server:path/project.git #dodanie zdalnego repozytorium
git remote show origin
git remote rename file1 file2git remote rm file
git clone [url] #klonowanie repozytorium, nie checkout, z pełną historią
git clone git://url [dir_name] #klonowanie z utworzeniem lokalnego katalog dir_name
git clone http(s)://git clone user@server:/path
git fetch origin #pobranie danych z serwera z aliasu “origin”, od ostatniego pobrania
git pull origin #j.w. wraz z mergowaniem
git push origin [branch_name] #wysłanie branch-a branch_name do zdalnego repozytorium
git push origin [branch_name] [remote_branch_name] #j.w. ze zmianą nazwy
git push origin :[branchname] #usunięcie zdalnego branch-a
schemat warstw:
working dir——-staging area——–git dir
układ katalogów:
.git/objects #all content
.git/refs #branches
.git/HEAD #currently checked out
.git/index #staging area (index)
Ostatnie komentarze