最近一直對(duì)git 小研究一下,發(fā)現(xiàn)還是有挺多之前不懂的得到了解答引谜,同時(shí)也有很多未知還要探索
1诀姚,git 的常用命令
這個(gè)很簡(jiǎn)單, 在命令行中寫(xiě)上 git help 就能看到
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>]
The most commonly used git commands are:
add Add file contents to the index
bisect Find by binary search the change that introduced a bug
branch List, create, or delete branches
checkout Checkout a branch or paths to the working tree
clone Clone a repository into a new directory
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
fetch Download objects and refs from another repository
grep Print lines matching a pattern
init Create an empty Git repository or reinitialize an existing one
log Show commit logs
merge Join two or more development histories together
mv Move or rename a file, a directory, or a symlink
pull Fetch from and integrate with another repository or a local branch
push Update remote refs along with associated objects
rebase Forward-port local commits to the updated upstream head
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index
show Show various types of objects
status Show the working tree status
tag Create, list, delete or verify a tag object signed with GPG
'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.
有幾個(gè)命令還是值得慢慢實(shí)踐來(lái)體會(huì)的
2 git 的狀態(tài)
在git 中只有3中狀態(tài) 1 已提交瞬捕,2 已修改 3 已暫存
git 基本流程
1 在本地修改了文件
2 對(duì)修改的文件進(jìn)行快照 -----》 保存到暫存區(qū)域
3 提交更新 將暫存的文件
這個(gè)是基本的git 管理流程,不能再基本了舵抹。
3 基本的提交
git add
git commit
git pull
git push
這個(gè)是我提交代碼的時(shí)候用的肪虎,當(dāng)然 add -a 全部文件, add - 具體文件名稱
commit -m""寫(xiě)下說(shuō)明什么的惧蛹,
pull --rebase , 衍合一下 push 就基本不加什么東西了. 可是最近研究發(fā)現(xiàn)扇救,這些基本的刑枝,不夠
那如何了解更多的?迅腔?装畅?
好奇心害死人,
在本地的是
git status 檢查當(dāng)前的狀態(tài)
通過(guò)add add 將文件放入暫存區(qū)
4 忽略文件
一般不想納入git 管理的沧烈,可是每次動(dòng)不動(dòng)還要你提交它掠兄,比較鬧心啊
建立 .gitignore 列出你不想要git 管理的文件
cat .gitignore
比如 忽略以 xx結(jié)尾的文件, *.xx
gitignore 也有自己的命名規(guī)范锌雀,這一個(gè)個(gè)規(guī)范我也是醉了蚂夕,為啥沒(méi)有統(tǒng)一的呢
表示注釋
最后以/結(jié)尾 表示忽略這個(gè)文件夾
可以使用glob 模式, 這個(gè)模式還是baidu 吧
5 git diff
查看尚未暫存的文件 ---更新什么呢
git diff
查看已經(jīng)暫存的文件和上次提交的快照 --快照 的之間差異
git diff --cached
6 git commit
所謂的暫存起來(lái)
這里感覺(jué)就一個(gè)地方 git commit -a - m ''''
不用寫(xiě)git add 了
7 git rm //git mv
這個(gè)還沒(méi)有研究
8 git log
這個(gè)幾個(gè)常用的 花樣
git log 簡(jiǎn)單粗暴
git log -p -2 //顯示最近2次你提交的內(nèi)容差異
單詞層面的對(duì)比 git log -U1 --word-diff
摘要行輸統(tǒng)計(jì)的對(duì)比 git log --state
針對(duì)信息格式的不同 git log --pretty= oneline / short /full /fuller
還有特別格式的腋逆。婿牍。。闲礼。牍汹。铐维。
9 git commit --amend
就是犯懶 柬泽,不想再寫(xiě)git add 如果有文件小改一下,可是剛剛提交了嫁蛇,而且還是對(duì)上個(gè)一個(gè)的補(bǔ)充锨并,就沒(méi)有必要寫(xiě)commit 的信息了,因?yàn)楹蜕蟼€(gè)的提交信息是一樣的
10 git reset HEAD + 文件名
取消了對(duì)文件的暫存
如何還沒(méi)有緩存 睬棚,就是手賤 不想要?jiǎng)偢膭?dòng)的東西了
用 git status
On branch develop
Your branch and 'origin/develop' have diverged,
and have 1 and 1 different commit each, respectively.
(use "git pull" to merge the remote branch into yours)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
提示你了第煮。哈哈。還是挺智能的啊
11 遠(yuǎn)程的倉(cāng)庫(kù) 查看
git remote -v
git remote add [shortname] [url] 這個(gè)shortname git fetch 會(huì)用到
比如: git remote add haha git://********* (url)
git remote show [remote-name] 遠(yuǎn)程倉(cāng)庫(kù)的信息
git remote rename haho tohehe //改名
git remote rm tohehe //刪除分之
12 git fetch [remote-name]
這個(gè)命令和git pull 經(jīng)常搞混
其實(shí)很容易分辨出來(lái)
fetch 僅僅負(fù)責(zé)---把遠(yuǎn)端的代碼拉取到本地 --不會(huì)合并到當(dāng)前的分支
pull 兩個(gè)都干了
13 git push [remote-name] [branch-name]
推送到遠(yuǎn)端
14 git tag
這個(gè)是標(biāo)簽列表
git tag -l 'v1.*' 模糊查詢
標(biāo)簽新建 1 lightweight 2 annotated
就是一個(gè)有簡(jiǎn)要信息一個(gè)沒(méi)有
git tag -a name -m'信息'
git show 查看標(biāo)簽的版本信息抑党, 打標(biāo)簽時(shí)候提交的對(duì)象
git tag 可以有后悔藥包警,在已經(jīng)提交的代碼中間打tag
git tag -a name 提交對(duì)象的校驗(yàn)和
git push origin [tagname] 提交標(biāo)簽 倉(cāng)庫(kù)名字不要忘記了
git 的最強(qiáng)大分支還沒(méi)有來(lái)得及研究本質(zhì),后續(xù)再寫(xiě)一個(gè)關(guān)于分支的底靠,git的基本技能才能基本ok