常用命令

對於任何一個文件,在 Git 內都只有三種狀態:已提交(committed),已修改(modified)和已暫存(staged)


git init

初始化新項目

git status

查看所有文件狀態

git add 

將文件添加到暫存區

git commit

提交暫存區文件

git log

查看提交歷史

git config --global user.name "<name>“

配置用戶姓名

git checkout –b feature dev

新建並切換到新功能分支

git add files

添加新文件到暫存區

git commit –a –m ‘修改原因’

將暫存區所有修改提交

git checkout dev

切換回開發分支

git merge –-no-ff feature 

合併新功能分支

git brance -d feature

 刪除新功能分支

git pull origin dev

獲取併合並遠程服務器最新代碼

git push origin dev

推送本地分支到遠程服務器對應分支

git push origin --delete <branchName>

刪除遠程分支

git push origin --delete tag <tagname>

刪除tag


初始化配置

mkdir testproject

cd testproject

git init

touch README

git add README

git commit -m 'first commit'

git remote add origin [email protected]:test.git

git  pull  --rebase origin master


忽略一些文件

.gitignore的文件


git 回滾單個文件

#git log 找到要回滾的commitID

#git checkout -m commitID  -- 文件路徑(相對路徑)


獲取所有分支到本地

remote=origin;for remotebr in `git branch -r | grep $remote | grep -v master | grep -v HEAD `; do git checkout --track $remotebr ; done

添加遠程倉庫

git remote add $remotename git://url

推送所有分支到遠程倉庫

git push --all $remote

推送所有tags

git push --tag $remote


分支操作

看各個分支最後一個提交對象的信息git branch -v

查看哪些分支已被併入當前分支git branch --merge 

查看尚未合併的工作 git branch --no-merged

使用-D強項刪除分支

本地一個新的分支,上傳到遠程

git push origin test:test

刪除遠程分支,本地仍會保留

$ git push origin :test

獲取遠程分支

git checkout -b release1.0.0 origin/release1.0.0

獲取不到遠程分支  

git remote show origin

git remote update

git fetch

git checkout -b local-name origin/remote-name

刪除不存在對應遠程分支的本地分支

查看分支狀況 git remote show origin

從本地版本庫中去除 git remote prune origin

本地配置

git config --global core.filemode false

git config --global core.safecrlf warn

git config --global core.autocrlf false

刪除已經提交過的文件

git rm --cached filename

#!/bin/sh

for fname in `find -maxdepth 5 -type d -regex '.*/[bB]in'`; do git rm -r --cached $fname ;done

for fname in `find -maxdepth 5 -type d -regex '.*/obj'`; do git rm -r --cached $fname ;done

for fname in `find -maxdepth 5 -type d -regex '.*/[Ll]og'`; do git rm -r --cached $fname ;done


恢復爲上傳的提交

git log 找到commontid

git reset --hard commontid


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