Git的結(jié)構(gòu):
- 工作區(qū): 在這里創(chuàng)建修改文件
- 暫存區(qū): 每次提交到倉庫前,先add到暫存區(qū),等待確認(rèn)
- 倉庫區(qū): 隱藏目錄,存儲各個歷史版本的文件
Git基本使用:
一. 文件目錄類
1. 建立目錄:mkdir 目錄名
2. 刪除空目錄:rmdir 目錄名
3. 無條件刪除子目錄: rm -rf 目錄名
4. 改變當(dāng)前目錄:cd 目錄名 (進(jìn)入用戶home目錄:cd ~;進(jìn)入上一級目錄:cd -)
5. 查看自己所在目錄:pwd
6. 查看當(dāng)前目錄大形龊:du
7. 顯示目錄文件列表:ls -l (-a:增加顯示隱含目錄)
其中:藍(lán):目錄;綠:可執(zhí)行文件;紅:壓縮文件;淺藍(lán):鏈接文件;灰:其他文件;紅底白字:錯誤的鏈接文件
8. 瀏覽文件:more 文件名.txt;less 文件名.txt
9. 復(fù)制文件: cp 源文件 目標(biāo)文件 (-r:包含目錄)
10. 查找文件:(1)find (2)locate 命令名
11. 鏈接:(1)建立hard鏈接:ln 來源文件 鏈接文件(-d:創(chuàng)建目錄鏈接)宵统;(2)建立符號鏈接:ln -s 來源文件 鏈接文件
12. 新建文件: touch *.txt
二. vi編輯類
1. 進(jìn)入后為命令模式:(1)插入i斥杜;(2)打開0;(3)修改c;(4)取代r;(5)替換s
2. 經(jīng)(1)后進(jìn)入全屏幕編輯模式产禾。
3. 命令模式-->編輯模式(a/i);編輯模式-->命令模式(Esc)牵啦;命令模式-->末行模式(:)亚情。
4. :w/w newfile保存
5. :q/q!退出vi(或者shift+zz退出);:wq保存退出
usage: git [--version] [--help] [-C <path>] [-c name=value]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]
These are common Git commands used in various situations:
start a working area (see also: git help tutorial)
clone Clone a repository into a new directory
init Create an empty Git repository or reinitialize an existing one
work on the current change (see also: git help everyday)
add Add file contents to the index
mv Move or rename a file, a directory, or a symlink
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index
examine the history and state (see also: git help revisions)
bisect Use binary search to find the commit that introduced a bug
grep Print lines matching a pattern
log Show commit logs
show Show various types of objects
status Show the working tree status
grow, mark and tweak your common history
branch List, create, or delete branches
checkout Switch branches or restore working tree files
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
merge Join two or more development histories together
rebase Reapply commits on top of another base tip
tag Create, list, delete or verify a tag object signed with GPG
collaborate (see also: git help workflows)
fetch Download objects and refs from another repository
pull Fetch from and integrate with another repository or a local branch
push Update remote refs along with associated objects
'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
Git基本操作流程
- Git在本地創(chuàng)建倉庫:
- git init 在當(dāng)前目錄下,創(chuàng)建一個倉庫./git隱藏的文件夾
- 當(dāng)前目錄是工作區(qū)
- Git向倉庫提交添加內(nèi)容:
- git add: 向暫存區(qū)添加內(nèi)容,有兩種方式: 一種
git add .
提交工作區(qū)全部文件;第二種git add filename
提交指定的文件.
- git commit -m "message for desc": 向倉庫提交內(nèi)容,一般注釋信息要求強(qiáng)制添加
- Git狀態(tài)查詢:
- git status: 顯示git當(dāng)前狀態(tài),如果工作區(qū),暫存區(qū)和倉庫的文件內(nèi)容一致,會顯示
working tree clean
- git log: 查看提交日志,可以看到每次修改操作的信息,包括:版本號,作者,日期和提交摘要,日志按時間順序排列,最上面的是與工作區(qū)一致的記錄,顯示
(HEAD -> master)
,依次是每次提交到倉庫的記錄日志,版本號$ commit 6d49af592cfce6a499f47b4ce2717a243abfb3e1
- Git刪除操作
- git rm filename: 刪除信息,實際是在暫存區(qū)記錄刪除的操作,然后還需要git commit,把這個刪除操作提交到倉庫,這樣倉庫會記錄下這一次更改的版本
- git reset --hard xxxx: 將當(dāng)前head指定到xxx版本(日志里commit后面的字符串),可以回滾到任意歷史版本
遠(yuǎn)程倉庫: Github and Bitbuckets
- Github開源
- 先在Github上新建倉庫create a new repository
- copy遠(yuǎn)程倉庫的地址,如:
https://github.com/ericoool/reading-notes.git
- 將本地倉庫的內(nèi)容提交到遠(yuǎn)程倉庫地址
- 同樣是先提交到暫存區(qū):
git remote add origin https://github.com/ericoool/reading-notes.git
- 然后push到倉庫:
git push -u origin master
- Bitbuckets私有
-