Git 經常使用命令

配置用戶

git config --global user.name "姓名"
git config --global user.email "郵箱"git

克隆倉庫

git clone <url>github

新建分支

基於masterfetch

git checkout -b new-branch-name -t master
git checkout -b new-branch-name origin/masterurl

拉取遠程分支,建立切換到本地分支
git checkout -b 本地分支 origin/遠程分支 (採用此種方法創建的本地分支會和遠程分支創建映射關係)code

創建兩個分支的映射
(將當前分支映射到遠程的指定分支,注意切換到當前分支)
git branch -u origin/遠程分支rem

切換分支

git checkout branch-nameit

查看本地狀態

git statusast

查看本地修改內容

git diffemail

比較本地文件和遠程文件的區別

git diff origin/master 文件路徑配置

在本地提交代碼某一文件

git commit -m '提交信息' filename.txt

在本地提交全部文件

git commit -m '提交信息' -a

更新分支到github

git push origin new-branch-name

刪除本地已被合併的分支

git fetch -p origin

讀取遠程倉庫修改

git fetch

遠程更新後將改動歸入本地分支

git rebase remote-branch

刪除遠程分支

git push origin :branch-name

拉取最新代碼:

git pull <remote> <branch>
git pull --rebase <remote> <branch>

強制更新單個文件:

1) git fetch
2) git checkout origin/master -- path/to/file

放棄本地修改,強制更新

1) git fetch --all
2) git reset --hard origin/master

fetch使用:

git fetch origin master:temp (採用此種方法創建的本地分支不會和遠程分支創建映射關係)
比較本地的倉庫和遠程參考的區別
$ git diff temp
合併temp分支到master分支
$ git merge temp
若是不想要temp分支了,能夠刪除此分支
$ git branch -d temp
相關文章
相關標籤/搜索