7、組件中名稱的設(shè)定
git update-ref refs/INIT/2b4549 使用引用名稱
git update-ref -d refs/INIT 刪除引用的名稱
git reset --hard INIT 還原到INIT的版本
git show-ref 查看引用名稱
git tag beta0.0.1 將當(dāng)前版本的名稱設(shè)置到標(biāo)簽中
git tag -d beta0.01 刪除標(biāo)簽
git tag 查看標(biāo)簽名稱
git rev-parse HEAD 引用名稱轉(zhuǎn)化為相對(duì)名稱(轉(zhuǎn)化為當(dāng)前版本的名稱)
git rev-parse HEAD~2 或 git rev-parse^^^^ 轉(zhuǎn)化到上二個(gè)版本
git rev-parser HEAD~1 或 git rev-parse^^ 轉(zhuǎn)化到上一個(gè)版本
8震叮、遠(yuǎn)程工廠和本地工廠交互
讓本地工廠和遠(yuǎn)程工廠進(jìn)行關(guān)聯(lián)
創(chuàng)建完遠(yuǎn)程工廠之后,就需要考慮如何和本地工廠進(jìn)行交互鳍鸵。此時(shí)會(huì)有幾種情況:
本地工廠已經(jīng)存在苇瓣,遠(yuǎn)程工廠未進(jìn)行初始化
本的工廠已經(jīng)存在,遠(yuǎn)程工廠已經(jīng)進(jìn)行初始化
本地工廠不存在偿乖,遠(yuǎn)程工廠未進(jìn)行初始化
本地工廠不存在击罪,遠(yuǎn)程工廠已經(jīng)初始化
以下是四種情況的模擬:
一、本地工廠已經(jīng)存在贪薪,遠(yuǎn)程工廠未進(jìn)行初始化
由于本地工廠已經(jīng)存在媳禁,需要將本地工廠與遠(yuǎn)程工廠進(jìn)行關(guān)聯(lián),來(lái)完成項(xiàng)目的上傳
Git用來(lái)模擬本地工廠已經(jīng)存在画切,遠(yuǎn)程工廠未進(jìn)行初始化
①先建立一個(gè)本地工廠
F:\git>mkdir Git
F:\git>cd Git
F:\git\Git>git init
Initialized empty Git repository in F:/git/Git/.git/
F:\git\Git>git st
?? git.txt
F:\git\Git>git add .
F:\git\Git>git co -m "git.txt"
[master (root-commit) 79b38d8] git.txt
1 file changed, 71 insertions(+)
create mode 100644 git.txt
②可以用git remote add origin https://github.com/yngy2016/test01來(lái)完成遠(yuǎn)程工廠的關(guān)聯(lián)
[remote "origin"]
url = https://github.com/yngy2016/Git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
origin 表示為遠(yuǎn)程工廠設(shè)定一個(gè)名稱损话,這時(shí)可以在.git中的config文件來(lái)看數(shù)據(jù)的添加,
url表示origin所對(duì)應(yīng)的遠(yuǎn)程工廠名稱
fetch表示在獲取遠(yuǎn)程工廠名稱時(shí)會(huì)根據(jù)這個(gè)引用名稱來(lái)獲取
③完成關(guān)聯(lián)的設(shè)置后使用git push master
來(lái)提交槽唾,會(huì)將本地工廠的數(shù)據(jù)提交到origin這個(gè)遠(yuǎn)程工廠的master分之中,第一次提交要輸入用戶名和密碼丧枪,以下是完成的提交代碼:
F:\git\Git>git push origin master
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 1.28 KiB | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/yngy2016/Git
* [new branch] master -> master
提交完成后遠(yuǎn)程工廠會(huì)有本地工廠的數(shù)據(jù)
使用git push --set-upstream origin master
可以將本地分支master注冊(cè)到.git/config文件中,之后使用git push就可以數(shù)據(jù)的提交庞萍,這種方式也可以用在master的其它分支上拧烦。
總結(jié):
①創(chuàng)建本地工廠
②創(chuàng)建遠(yuǎn)程工廠,并不初始化
③使用git remote add origin https://github.com/yngy2016/Git```來(lái)進(jìn)行工廠的關(guān)聯(lián)钝计。 ④使用```git push origin master```來(lái)提交 ⑤使用```git push --set-upstream origin master```可以注冊(cè)分支 ⑥在使用
git push``就可以完成數(shù)據(jù)的提交
二恋博、本的工廠已經(jīng)存在齐佳,遠(yuǎn)程工廠已經(jīng)進(jìn)行初始化
**git_init用來(lái)模擬本地工廠已經(jīng)存在,遠(yuǎn)程工廠已經(jīng)進(jìn)行初始化****
①先建立本地工廠
②建立遠(yuǎn)程工廠并初始化之后债沮,使用git remote push master https://github.com/yngy2016/git_init
來(lái)完成工廠關(guān)聯(lián)時(shí)會(huì)出現(xiàn)以下代碼:
To https://github.com/yngy2016/git_init
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/yngy2016/git_init'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
這是因?yàn)橐呀?jīng)在遠(yuǎn)程工廠中的數(shù)據(jù)已經(jīng)初始化炼吴,并且創(chuàng)建了一個(gè)master分支,會(huì)與本地工廠的數(shù)據(jù)沖突疫衩,這時(shí)使用git push master
依然會(huì)報(bào)錯(cuò)硅蹦,需要更新數(shù)據(jù)來(lái)完成提交,獲取遠(yuǎn)程工廠的命令是git pull master
會(huì)出現(xiàn)以下代碼:
warning: no common commits
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/yngy2016/git_init
* branch master -> FETCH_HEAD
* [new branch] master -> origin/master
fatal: refusing to merge unrelated histories
這是因?yàn)檫h(yuǎn)程工廠與本地工廠還沒(méi)有進(jìn)行關(guān)聯(lián)闷煤,無(wú)法合并分支童芹,就需要加入?yún)?shù)--allow-unrelated-histories
來(lái)進(jìn)行遠(yuǎn)程工廠的數(shù)據(jù)獲取。
F:\git\git_init>git pull origin master --allow-unrelated-histories
From https://github.com/yngy2016/git_init
* branch master -> FETCH_HEAD
Merge made by the 'recursive' strategy.
README.md | 1 +
1 file changed, 1 insertion(+)
create mode 100644 README.md
③使用git log
來(lái)查看版本鲤拿,共有三個(gè)版本:
F:\git\git_init>git log
commit dbac23e0a2ecca66798c222dafabc1774008b03c
Merge: 62a8b56 7614851
Author: yngaoyan <yngaoyan@gemil.com>
Date: Sun Apr 23 17:54:01 2017 +0800
Merge branch 'master' of https://github.com/yngy2016/git_init
commit 62a8b569016bcfb40a2c60efacac69ef051de6e9
Author: yngaoyan <yngaoyan@gemil.com>
Date: Sun Apr 23 17:46:42 2017 +0800
git_init.txt
commit 76148511272d4624c8150d79890bd53fd34fca29
Author: yngy2016 <2269904451@qq.com>
Date: Sun Apr 23 17:43:58 2017 +0800
Initial commit
第一個(gè)版本是在遠(yuǎn)程工廠中初始化并提交的版本 Initial commit假褪,第二個(gè)是版本是在本地工廠初始化并提交的版本git_init.txt,第三個(gè)版本是最新版本近顷,是兩個(gè)的合并版本生音,之后在使用git push master
就可以完成本地工廠的提交。
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (5/5), 494 bytes | 0 bytes/s, done.
Total 5 (delta 0), reused 0 (delta 0)
To https://github.com/ynkonghao/test1_init.git
263dab7..3395ef6 master -> master
Branch master set up to track remote branch master from origin.
總結(jié):
①建立本地工廠和遠(yuǎn)程工廠,并初始化遠(yuǎn)程工廠
②使用git pull origin master --allow-unrelated-histories
從遠(yuǎn)程工廠中獲取數(shù)據(jù)并合并到本地工廠中
③使用git log
來(lái)查看版本的信息
④使用git push master
來(lái)完成提交
三窒升、本地工廠沒(méi)有建立久锥,遠(yuǎn)程工廠已經(jīng)進(jìn)行初始化
**fac_init用來(lái)模擬本地工廠沒(méi)有建立,遠(yuǎn)程工廠已經(jīng)進(jìn)行初始化****
①現(xiàn)在建立遠(yuǎn)程工廠并初始化
②使用git clone https://github.com/yngy2016/fac_init
把遠(yuǎn)程工廠的數(shù)據(jù)克隆到本地工廠异剥,會(huì)出現(xiàn)以下代碼,本地就會(huì)出現(xiàn)一個(gè)fac_init的文件絮重,里面的數(shù)據(jù)和遠(yuǎn)程工廠的一樣冤寿。
Cloning into 'fac_init'...
remote: Counting objects: 21, done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 21 (delta 5), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (21/21), done.
③進(jìn)入fac_init文件夾使用git log可以看到工廠中已經(jīng)有一次master分支的提交
④之后添加數(shù)據(jù)只需要git push
就能把數(shù)據(jù)提交到遠(yuǎn)程工廠的master分支中
F:\git\fac_init>git push
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 294 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/yngy2016/fac_init
fdb0254..6b4bee2 master -> master
總結(jié):
①建立遠(yuǎn)程工廠并初始化,沒(méi)有本地工廠
②使用git clone https://github.com/yngy2016/fac_init
把遠(yuǎn)程工廠的數(shù)據(jù)克隆到本地工廠
③使用git push
提交數(shù)據(jù)
四青伤、本的工廠不存在督怜,遠(yuǎn)程工廠沒(méi)有初始化
fac用來(lái)模擬遠(yuǎn)程工廠未已經(jīng)行初始化
①本地工廠不存在和遠(yuǎn)程工廠沒(méi)有初始化
②當(dāng)時(shí)用git clone https://github.com/yngy2016/fac
時(shí)會(huì)報(bào)錯(cuò)代碼如下:
Cloning into 'fac'...
warning: You appear to have cloned an empty repository.
③要先在本地工廠建立第一個(gè)版本
F:\git>cd fac
F:\git\fac>git add .
F:\git\fac>git st
A fac.txt
F:\git\fac>git co -m "fac.txt"
[master (root-commit) 547f031] fac.txt
1 file changed, 9 insertions(+)
create mode 100644 fac.txt
F:\git\fac>git push
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 468 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/yngy2016/fac
* [new branch] master -> master