刪除工作區 git checkout – file 1.checkout帶–
1.reset 暫存區撤銷,重新放回工作區 git reset head file
git checkout 2.切換到另乙個分支
git reset 2.reset回退版本 head 表示最新的版本 head^上乙個 head^^上上個
head~100 前100個
從暫存區提交到了版本庫
git reset –hard head^
gti reset –hard 1234567 回退到上乙個版本
git log 檢視提交歷史
回到未來 git reflog
git rm 從版本庫中刪除 git rm file 並且 git commit
刪錯了從版本庫恢復 git checkout –test.txt
git checkout其實是用版本庫里的版本替換工作區的版本,無論工作區是修改還是刪除,都可以「一鍵還原」。
關聯乙個遠端庫 git remote add origin git@server-name:path/repo-name.git
git push -u origin master 推送master分支所有內容
由於遠端庫是空的,我們第一次推送master分支時,加上了-u引數,git不但會把本地的master分支內容推送到遠端新的master分支,還會把本地的master分支和遠端的master分支關聯起來,在以後的推送或者拉取時就可以簡化命令
檢視分支 git branch
建立分支 git checkout -b branch-name | git branch branch-name
切換分支 git checkout branch-name
合併某分支到當前分支 git merge branch-name
刪除分支 git branch -d
git merge –no-ff -m 「merge with no-ff」 dev 合併dev分支 禁用fast forward 因為本次合併要建立乙個新的commit,所以加上-m引數,把commit描述寫進去。
git merge dev 如果沒有衝突 git快速合併
指定本地分支與遠端分支的鏈結 git branch –set-upstream branch-name origin/branch-name
推送 git push origin branch-name
git pull 拉最新版本
git remote -v 檢視遠端庫資訊
git checkout -b branch-name origin/branch-name
git tag 打新標籤
git tag 檢視所有標籤
git tag tag-name commit-id 為過去版本加tag
檢視標籤 git show
git tag -a tag-name -m description commit-id 建立帶有說明的標籤
git show 看說明文字
git tag -s tag-name -m 『…』 commit-id 通過-s 用私鑰簽名乙個標籤(pgp簽名)
git tag -d tag-name 刪除標籤
git push origin
git push origin 推送乙個本地標籤
git push origin –tags 推送全部未推送過的本地標籤
git push origin :refs/tags/ 刪除乙個遠端標籤
附git-power整理內容如下
git常用操作
git是一款分布式的版本控制軟體,相比svn,功能更強大,自然而然操作更複雜一些。git在本地也是以git版本庫的形式管理,而svn在本地管理的僅是乙個版本庫的副本。很明顯的乙個不同點 git你可以在本地做一些修改,然後commit到本地的版本庫,最後push到伺服器,而svn只要一commit,更...
Git常用操作
有時候我們需要修改之前提交的時候的說明資訊,沒有操作命令可以直接完成,但是使用rebase命令可以實現。例如我們要修改倒數第二次的提交的說明資訊 git rebase i head 3 注意 這裡head 後面跟著的是3而不是2,因為這裡指的是要修改的提交的父提交。之後會進入到文字編輯介面,如下圖 ...
Git常用操作
這裡記錄目前我最常用的操作。因為是最常用的,就不包括什麼建立倉庫,設定使用者資訊啊,這種設定一次的了。先上一張圖 1.分支管理 檢視本地分支 git branch 檢視所有分支 本地 遠端 git branch a 建立分支 git branch 切換分支 git checkout 建立 切換分支 ...