Git 教程

查看分支:

1、查看本地分支:

git branch

2、查看遠程分支:

git branch -r

新建branch:

git checkout -b abc_branch

刪除分支

git branch -d abc_branch
強制刪除使用 -D

切換branch

git checkout abc_branch

合併分支

git merge abc_branch

git 查看記錄

git blame filename 查看該文件目前的每一行最後改動的是什麼時候提交的
git log -p filename 查看這個文件所有的詳細提交

查看某一個文件的所有提交記錄:
1、 git log --pretty=oneline 文件路徑

例子:git log --pretty=oneline views.py
f850a9ef393584e49d46391897db614ed56a2903 third commit
0d08b578371afb8f45748a0491faa2a7820d7928 second commit
3fcc3973deee5c33695c0b40b18a11f83c986b2d first commit

2、git show 3fcc3973deee5c33695c0b40b18a11f83c986b2d

例子裏面打印出來的就是針對文件views.py的所有的改動歷史,每一行最前面的那一長串數字就是每次提交形成的哈希值,接下來使用git show即可顯示具體的某次的改動的修改

git stash

用來暫存當前正在進行的工作, 比如突然你想pull 最新代碼, 又不想加新commit, 或者另外一種情況,爲了fix 一個緊急的bug,
先stash, 使返回到自己上一個commit, 改完bug之後再stash pop, 繼續原來的工作。

git stash 
做一些操作後 
git stash list 查看stash 列表 
git pop 將最近的一個取出,並且刪除

if你的stash裏面有好多個,這個時候可以使用git stash list 將Git棧信息打印出來,然後git stash apply stash@{0},取出對應的,注意這個時候並沒有清除,如果需要清除,git stash clear,清空


git pull –rebase

當本地commit一個提交和遠端服務器中的代碼有衝突(別人也改了相同的文件)時可以在pull 中加 –rebase。
加上 rebase 的意思是:

git pull --rebase

把本地 repo. 從上次 pull 之後的變更暫存起來
恢復到上次 pull 時的狀態
合併遠端的變更到本地
最後再合併剛剛暫存下來的本地變更


git commit –amend

git commit --amend 可以修改最後一次 commit
  1. // 查看修改
    gi rebase -i master~1 //最後一次
    git rebase -i master~5 //最後五次
  2. // 顯示結果如下,修改 pick 爲 edit ,並 :wq 保存退出
    pick 92b495b 2009-08-08: ×××××××
    Rebase 9ef2b1f..92b495b onto 9ef2b1f
    Commands:
    pick = use commit
    edit = use commit, but stop for amending //改上面的 pick 爲 edit
    squash = use commit, but meld into previous commit
    If you remove a line here THAT COMMIT WILL BE LOST.
    However, if you remove everything, the rebase will be aborted.
  3. 命令行顯示:
    Rebasing (1/1)
    You can amend the commit now, with
    git commit –amend
  4. 使用 git commit –amend 進行修改,完成後 :wq 退出
  5. 使用 git rebase –continue 完成操作

git checkout

git 返回到某個節點的文件

git checkout 1bbbb91aaf96f1274750c6fd21d77c5e7142d424 文件路徑

git 有用的小貼士

內建的git輸出 gitk
彩色的git輸出 git config color.ui true
git config format.pretty oneline


GIT CLONE ERROR

git config --global http.postBuffer 24288000
git config --list
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章