Академический Документы
Профессиональный Документы
Культура Документы
2. Github l g?
C th gip quy trnh lm vic code theo nhm n gin hn rt nhiu bng
vic kt hp cc phn nhnh (branch).
V nhiu hn th na.
Untracked
Nu bn to ra hoc thm vo mt tp tin mi vo trong th mc lm vic ca bn
th n s trng thi Untracked. By gi mnh th to ra mt tp tin mi tn
l faq.html, sau dng lnh git status xem trng thi ca Git trong th mc lm
vic.
$ touch faq.html
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
faq.html
nothing added to commit but untracked files present (use "git add" to track)
Note: Lnh touch l to ra mt tp tin rng.
By gi bn s thy n lit k ra tn tp tin ang trng thi Untracked. a
n v Tracked bn s s dng lnh git add v xem li trng thi ca n.
$ git add faq.html
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: faq.html
Bn c thy s k l tp tin faq.html khng? l n c hin th hai trng thi
Staged (c th commit) v Modified (khng th commit) hay cn gi l Unstaged. S
d c s k l y l bi v trc bn to ra tp tin faq.html v a v
Tracked th n cng c a v Staged c th commit. Tuy nhin sau bn
li chnh sa ni dung ca n nn n c mt phin bn khc nm trng thi
Modified (khng th commit). Nu by gi bn g lnh git commit y thc n th
bn chp ca tp tin faq.html ln cui cng bn g lnh git add s c commit
ln ch n khng cha cc ni dung m bn va thm vo. V n c th commit
tp tin faq.html c chnh sa th bn phi g li lnh git add faq.html ln na.
8. Chuyn tp tin t Untracked v Tracked
Trong Git, bn c th a mt tp tin t Tracked v Untracked vi lnh rm tn_file.
Lnh rm s gip bn a tp tin v trng thi Untracked nhng khng xa hn trong
cng.
$ rm faq.html
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
deleted: faq.html
Cn nu bn mun xa n lun th dng lnh git rm -f tn_file v nh cn thn khi
dng lnh ny.
Xem git log
xem lch s ca cc ln commit trc , bn s dng lnh git log l s thy.
$ git log
commit ab5f22d697b238ace4bbb221c53c12a3df9d132d
Author: QuangHD <quanghd@fpt.edu.vn>
Date: Wed Sep 21 14:16:44 2016 +0700
commit 5845e2830672f3ca0ab2ebe37ee0d58f5aeb5ba9
Author: HocLT <hdquang6@gmail.com>
Date: Wed Sep 21 14:13:25 2016 +0700
Initial commit
Bn thy ch? Mi ln commit s c mt checksum ring, v n cng c ghi r ai l
ngi commit vo v commit vo ngy bao nhiu, lc no.
Ngoi ra, bn c th chn thm tham s -p vo hin th chi tit ca mi ln
commit.
$ git log -p
commit ab5f22d697b238ace4bbb221c53c12a3df9d132d
Author: QuangHD <quanghd@fpt.edu.vn>
Date: Wed Sep 21 14:16:44 2016 +0700
commit 5845e2830672f3ca0ab2ebe37ee0d58f5aeb5ba9
Author: HocLT <hdquang6@gmail.com>
Date: Wed Sep 21 14:13:25 2016 +0700
Initial commit
V d:
$ >git log --author=quanghd@fpt.edu.vn --pretty="%s"
%H Commit hash
%T Tree hash
%P Parent hashes
%s Subject
V d:
$ git log --pretty="%an - %s"
QuangHD - First commit on Github
HocLT - Initial commit
Undo Commit
Nu bn cn xa b ln commit trc v cn undo commit li th c th s dng
tham s --amend trong lnh git commit.
$ git log --pretty="%s"
First commit on Github
Initial commit
$ git commit --amend -m "First commit on Github"
[master 14cec0d] First commit on Github
Date: Wed Sep 21 14:16:44 2016 +0700
1 file changed, 1 insertion(+)
create mode 100644 data.txt
$ git log --pretty="%s"
First commit on Github
Initial commit
Lu rng undo ngha l bn quay tr li bc commit ln trc, do vy nu cn b
sung tp tin no vo commit th hy a tp tin vo Staging Area trc.
10.
i tn remote
Thm mt remote
$ git remote -v
C:\Users\Quang\Documents\MyGit\demo-git>git remote -v
googleandroid https://github.com/googlesamples/google-services (fetch)
googleandroid https://github.com/googlesamples/google-services (push)
quanghd https://github.com/HocLT/demo-git (fetch)
quanghd https://github.com/HocLT/demo-git (push)
Sau nu bn mun ly d liu t ci googleandroid kia v th ch cn s dng
lnh git fetch googleandroid.
$ git fetch googleandroid
warning: no common commits
remote: Counting objects: 5234, done.
remote: Compressing objects: 100% (16/16), done.
rRemote: Total 5234 (delta 3), reused 0 (delta 0), pack-reused 5218eceiving objects:
98% (5180/5234), 8.04 MiB | 10.00 KiB/s
Receiving objects: 100% (5234/5234), 8.10 MiB | 15.00 KiB/s, done.
Resolving deltas: 100% (2447/2447), done.
From https://github.com/googlesamples/google-services
* [new branch]
master
-> googleandroid/master
git pull
Lnh ny s t ng ly ton b d liu t remote repository v gp vo ci branch
hin ti bn ang lm vic.
git fetch
Lnh ny s ly ton b d liu t remote repository nhng s cho php bn gp
th cng vo mt branch no trn th mc Git my tnh.
14.
HEAD con tr v tr
Trc khi ni tip v branch th mnh xin ni qua mt xu vHEAD. Trong Git, t kha
HEAD s tng trng cho con tr ch cho bn bit bn ang nm u. By gi hy
xem li bi hng dn c log commit ca mnh, tm ti phn ti u log v ci vo.
Sau g lnh git lg th bn s thy t kha HEAD cho bn bit bn ang u
trong working tree.
Gp d liu t mt branch
Xa branch
master
Already up-to-date.
-> FETCH_HEAD
Automatic merge failed; fix conflicts and then commit the result.
C th n s xy ra li conflict khi gp file README.md cng khng quan trng lm
nn bn c th b qua bng cch g lnh git add README.md track file ny, v
by gi nu bn g lnh ls ra th c cc file t googleandroid ri.
By gi bn c th commit n v th push n ln repository ca bn.
$ git commit -m "Commit from android"
[android d176e9f] Commit from android
$ git push googleandroid android
Yu cu nhp username v password ca repository
https://github.com/googlesamples/google-services ny, nhng y l repository
mnh ly tm demo nn khng c ti khong ???
Nhc li rng, thach ngha l tn remote ca repository m mnh cn push ln
v android l tn branch mnh cn push.
Bn cng c th qua mt branch khc v s dng lnh git merge gp d liu ca
branch ny v.
Ngoi ra, kin thc v branch cn c mt k thut na cng kh th v m khi lm
vic nhm c th s cn n, l rebase branch vi mc ch hon i v tr ca
nhng ln commit.
20.
c. Assembla