1、把暫存區內容回滾的工作區,回退到上一個版本
$ git reset HEAD text.txt
2、撤銷修改:1. 文件在添加到緩存區前修改,則回退到原工作區狀
態;
$ git checkout -- text.txt
3、查看歷史提交記錄
$ git log
4、回退到歷史指定版本
$ git reset --hard ae0e2a5385a11917816b3f161adc19f7e53ba845
5、清空本地文件text.txt
$ git rm text.txt
6、從暫存區直接刪除文件
rm -cacheed
7、除當前目錄下的所有文件及目錄,命令行爲:
rm -r *
$ git rm --cached text.txt
8、將文件提交到倉庫(把暫存區的所有內容提交到當前分支)
$ git commit -m "wrote a readme.txt."
9、確認刪除後,提交到版本庫
$ git commit -m "remove test.txt"
10、將文件提交到倉庫(把暫存區的所有內容提交到當前分支)
$ git commit -m "wrote a readme.txt."
11、一次性提交3個文件
$ git commit -m "add 3 files."
12、將文件提交到倉庫,並註釋內容
git commit -m "delete bash demo"
13、git提交代碼出現錯誤fatal: Unable to create '項目路
徑/.git/index.lock': File exists.在.git上級目錄操作
rm -f ./.Git/index.lock
-----------------------------------
14、遠程倉庫新建ssh
$ ssh-keygen -t rsa -C "[email protected]"
15、回到當前目錄的主目錄
cd ~
16、回到主目錄
$ pwd
17、顯示.ssh
cd .ssh
18、查看詳細信息
$ ll
19、查看公鑰內容,文件內容
$ cat id_rsa.pub
20、查看是否github是否連接成功
$ ssh -T [email protected]
21、直接跳轉到指定子目錄
$ cd /f/gitdemo
22、查看所有文件
$ ls -a
23、新增一個文件.md
$ echo“#newdemo”>> README.md
24、查看詳細信息
$ ll
25、初始化git
$ git init
26、追加文件到緩存區
$ git add README.md
27、提交到本地庫
$ git commit -m "first commit"
28、關聯遠程庫
$ git remote add origin
https://github.com/liminga/newdemo.git
29、追加內容到遠程,第二次不用-u
$ git push -u origin master
30、文本追加內容
$ vim README.md
31、退出文本
Esc :wq
32、追加到緩存
$ git add README.md
32、提交到本地庫
$ git commit -m "second commit "
33、追加到遠程庫
$ git push
--------------------------------
// 4.6 多人協作(最好結合工作場景理解)
git remote -v // 查看遠程庫詳細信息
git push origin dev // push本地dev分支到遠程dev
git push origin master // push本地master分支到遠程master(時刻保持同步)
git pull // 將最新的pull/dev(master)爬下來
git checkout -b branch-name origin/branch-name // 在本地創建和遠程分支對應的分支
git branch --set-upstream-to=origin/<branch> dev // 建立本地分支和遠程分支的關聯
// 4.7 Rebase
git rebase // 將本地未push的分支提交整理成直線,利於查看
--------------------------------
34、克隆倉庫
git clone https://github.com/liminga/clone_demo.git
34-2、以Https協議方式克隆
$ git clone https://github.com/ChrisLeejing/gitskills.git
35、新增一個txt文件,內容爲clone demo
$ echo "clone demo" >> clone.txt
36、追加到遠程庫
$ git push
----------------------------------
標籤管理
37、查看所有標籤
git tag
38、創建標籤
git tag v1.0.1
39、指定提交信息
git tag -a name -m "comment"
40、刪除標籤name
git tag -d v2.0.1
41、標籤發佈v1.0.1
git push origin v1.0.1
42、切換到標籤與切換分支命令相同
git checkout [tagname]
43、從遠程刪除。刪除命令也是push,但是格式如下:
$ git push origin :refs/tags/v1.0.1
--------------------------------------------
分支管理
44、創建文件夾Git
$ mkdir Git
45、查看所有分支(當前分支以‘*’標記)
git branch
46、創建分支(如:git branch dev)
git branch <name>
47、切換分支
git checkout <name>
48、創建切換分支(如:git checkout -b dev)
git checkout -b <name>
49、合併分支到當前分支上
git merge <name>
49-2、合併分支到master分支上
git checkout master
git merge <name>
50、刪除該分支
git branch -d <name>
51、查看分支合併圖
git log --graph
52、查看分支合併縮略圖
git log --graph --pretty=oneline --abbrev-commit
----------------------------------------------------------------------------------------
git
1、下載地址 window git
https://git-scm.com/download/win
2、配置用戶信息
用戶名稱:$ git config --global user.name "tyler"
用戶地址:$ git config --global user.email "[email protected]"
2-1查看用戶名和郵箱地址:
$ git config user.name
$ git config user.email
3、初始化版本庫
- git init
4、添加文件到版本庫
- git add
- git commit
5、查看倉庫狀態
- git status
6、命令
顯示當前所在位置
$pwd
建立時間詳細信息
$ ll
到上級目錄
$ cd ..
到d盤
$ cd /d
創建文件夾
$ ls
回到剛纔的目錄
$ cd -
清屏
$ clear
查看git版本
$ git --version
顯示目錄下內容
$ ls -ltr
創建temp目錄
$ mkdir temp
$ cd temp
$ pwd
git初始化
$ git init
查看生成的隱藏文件
$ ls -a
生成文件
$ echo "git repo2" >> test.txt
$ ll
展示當前文件內的內容
$ cat test.txt
--提交,並m註釋
$ git commit -m "Init Project"
查看當前文件狀態
$ git status
查看.git內的文件
$ ls -l .git
配置全局的用戶名和郵箱信息
$ git config --global user.name 'Wenjie Zhang'
$ git config --global user.email '[email protected]'
回到軟件的系統工作目錄
$ cd ~
--查看.gitconfig的內容
$ cat.gitconfig
--顯示用戶信息
$ id
--查看 .git下的內容
$ ls -l .git
--查看配置後的內容
$ cat .git/config
$ pwd
$ ls -l
--增加main.c到git中
$ git add main.c
--提交,並m註釋
$ git commit -m "Init Project"
--創建文件
vi main.c
int main()
{
return 0;
}
ls -l
--查看.git的目錄內容
$ ls -l .git
--刪除剛剛提交的main.c文件
$ rm -f main.c
--確認沒有了
$ ls -ltr
$ ls -l
$ ls -la
--使用git恢復main.c文件
git checkout -f HEAD
--查看是否恢復成功
ls -l
--創建新的文件夾ccc,進入到ccc文件夾
mkdir ccc
cd ccc
--拷貝bbb下的main.c文件到當前目錄
cp ../bbb/main.c .
--查看確認
ls -ltr
--初始化git
git init
--查看main.c的內容
cat main.c
--查看main.c的hash值
git hash-object main.c
--添加當前文件夾的內容到git中
git add .
--顯示.git下的內容
ls -l .git
--顯示.git/objects下的內容
ls -l .git/objects/
--顯示.git/objects/fc下的內容,實際上是main.c的hash的頭兩個字母
ls -l .git/objects/fc
--提交,並註釋
git commit -m "1 commit"
clear
ls -l .git/objects/
--找到.git/objects/下所有類型爲文件的對象
find .git/objects/ -type f
--顯示fc047f開頭的文件的內容
git show fc047f
--查看0593開頭的文件的類型
git cat-file -t 0593
clear
find .git/objects/ -type f
--查看commit類型文件的內容
git show -s --pretty=raw 2364
------------------------------------------------------------------------------
--演示多文件,多目錄下的blob和tree和commit的數量
--新建ddd文件夾
mkdir ddd
cd ddd
--新建 lib文件夾
mkdir lib
cd lib
--新建inc文件夾
mkdir inc
cd inc
ls
--inc下創建 trick.rb文件
vi trick.rb
sssssss
:x
cd ..
--lib下創建mylib.rb文件
vi mylib.rb
this is mylib.rb
:x
cd ..
--ddd下創建見READE文件
vi README
this is ReadMe
:x
--初始化,添加,提交
git init
git add .
git commit -m "this is first commit"
--查看生成的文件數,應該是3個blob文件3個tree文件1個commit文件
find .git/objects/ -type f
git cat-file -t ****
cd ..
-------------------------------------
--研究HEAD對象
--創建eee文件夾
mkdir eee
cd eee
--拷貝ddd的文件過來
cp ../ddd/README .
clear
--確認拷貝
ls -ltr
--初始化
git init
--添加
git add .
--提交
it commit -m "this is first commit"
--顯示文件下的對像
ls -l .git/objects/
--顯示對象爲文件的對象
find .git/objects/ -type f
ls -l .git
--查看HEAD的內容
cat .git/HEAD
ls -l .git/refs/
ls -l .git/refs/heads/
--HEAD的內容是一個引用,查看指向的內容
cat .git/refs/heads/master
--指向的內容是那個對象的hash碼
find .git/objects/ -type f
--查看該對象的類型,應該爲commit
git cat-file -t ****
----------------------------
--研究tag,有引用和對象兩種形式
--進到ddd文件夾
cd ddd
ls -l
--查看當前生成的對象數,7
find .git/objects/ -type f | wc -l
--修改最底層的文件
vi /ddd/lib/ind.trick.rb
*****
:x
pwd
--添加提交
git commit -a -m "second commit"
----查看當前生成的對象數,12
find .git/objects/ -type f | wc -l
ls -l .git
ls -l .git/refs/tags
輕量級的tags
git tag v1.0
ls -l .git/refs/tags
cat .git/refs/tags/v1.0
--查看標籤指向對象類型
git cat-file -t ****
--commit
--查看當前生成的對象數,還是12,沒有生成標籤對象
find .git/objects/ -type f | wc -l
--打標籤,這個會生成標籤對象
git tag -a milestone1.0 -m "this is the first stable version"
--查看當前生成的對象數,13
find .git/objects/ -type f | wc -l
ls -l .git/refs/tags/
--查看標籤內容
cat .git/refs/tags/milestone1.0
--查看標籤指向對象,爲tag
find .git/objects/ -type f
git cat-file -t ****
--tag
--再次修改文件
vi init.rb
....
--第三次打標籤
git commit -a -m "third commit"
----查看當前生成的對象數
find .git/objects/ -type f | wc -l
--查看頭文件內容
cat .git/HEAD
cat .git/refs/heads/master
cat .git/refs/tags/v1.0
--頭文件還是指向的最新的commit對象
git cat-file -t df87
--commit
git cat-file -t 9e7b
--commit
cat init.rb
--發佈tag爲v1.0時的版本,格式爲tar,目錄在ruby下,用gzip加壓,生成在/tmp//tmp/ruby1.0.tar.gz下
git archive --format=tar --prefix=ruby/ v1.0 | gzip > /tmp/ruby1.0.tar.gz
cd /tmp
ls -l
-檢驗生成的結果
tar zxvf ruby1.0.tar.gz
-----------------------------
pwd
ls -l
ls -la
--初始化,加載,提交
git init
git add .
git commit -m "1st commit"
--查看文件個數
find .git/objects/ -type f | wc -l
--查看分支情況
git branch
clear
--查看頭文件
ls -l .git/HEAD
cat .git/HEAD
cat .git/refs/heads/master
--指向的文件類型
git cat-file -t ****
--修改文件
vi test.rb
--第二次提交
git commit -a -m "2nd commit"
--修改文件
vi README
--第三次提交
git commit -a -m "3rd commit"
--產生testing分支
git branch testing
--查看頭引用指向
cat .git/HEAD
ls -l .git/refs/heads
--查看兩個分支的指向,是一樣的
cat .git/refs/heads/master
cat .git/refs/heads/testing
git breach
--切換分支
git checkout testing
git breach
--查看頭文件指向
cat .git/HEAD
clear
git breach
ls
--修改test.rb文件
vi test.rb
--第四次提交
git commit -a -m "testing 4th commit"
--查看當前的HEAD引用
cat .git/HEAD
--查看當前的testing和master分支,應該已經不同了
cat .git/refs/heads/testing
cat .git/refs/heads/master
cat test.rb
--切換到master分支
git branch
git checkout master
--顯示test.rb文件
cat test.rb
--切回到testing分支
git branch
git checkout testing
git branch
cat test.rb
clear
--切回到master分支
git branch
git checkout master
ls
-修改LICENSE2文件
vi LICENSE2
--master第四次提交
git commit -a -m "master 4th commit"
clear
--合併前master情況
git branch
ls -l
cat LICENSE2
cat test.rb
cat README
--合併前testing情況
git checkout testing
cat LICENSE2
cat test.rb
cat README
clear
--合併
git branch
git checkout master
git merge testing
clear
ls
ls -l
--合併後的情況
cat LICENSE2
cat test.rb
cat README
--刪除testing分支
git branch
it branch -D testing
git branch
clear
cd ..
ls
--創建新的工作區
mkdir fw
cd fw
ls
vi main.c
ls
git init
git add .
git commit -m "1st commit"
ls
ls -l
--創建tempbr分支
git branch
git branch tempbr
git checkout tempbr
--分支的文件已經改變,提交
vi main.c
git commit -a -m "tempbr 2nd commit"
--master分支沒有變化
git branch
git checkout master
cat main.c
--此時合併更容易
git merge tempbr