Git常用命令整理(慢慢更新)

一般常用命令

git init //生成.git目錄
git add . //把當前目錄裏的文件加入到暫存區
git add README //更新README文件
git commit -m ‘上傳’ //從暫存區提交到倉庫
git remote add origin 遠程倉庫地址 //添加遠程倉庫
git branch --set-upstream-to=origin/ master //本地倉庫和遠程倉庫關聯,git pull時就會有提示
git status //會有信息顯示:Your branch is up-to-date with ‘origin/master’.不過一般遠程倉庫會和現有倉庫合併不了,單純的git pull會提示fatal: refusing to merge unrelated histories

git pull --rebase origin master //看來以rebase變基的方式可以合併啊
git push //提交到遠程倉庫
git push -u origin master

大文件

上傳大文件報錯remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.

git lfs install //安裝LFS
git lfs track ".a" //".a"是上傳的大文件路徑
git add .gitattributes //添加,相當於add .
git add 大文件 //添加大文件到本地緩存區
再commit>>push

其他

git config --global core.autocrlf false //關閉自動換行
git config --global core.safecrlf true

git tag # 列出當前倉庫的所有標籤
git tag -l ‘v0.1.*’ # 搜索符合當前模式的標籤
git tag v0.2.1-light # 創建輕量標籤
git tag -a v0.2.1 -m ‘0.2.1版本’ # 創建附註標籤
git checkout [tagname] # 切換到標籤
git show v0.2.1 # 查看標籤版本信息
git tag -d v0.2.1 # 刪除標籤
git tag -a v0.2.1 9fbc3d0 # 補打標籤
git push origin v0.1.2 # 將v0.1.2標籤提交到git服務器
git push origin --tags # 將本地所有標籤一次性提交到git服務器
git tag # 查看當前分支下的標籤

變更項目地址

git remote set-url origin [email protected]:res_dev_group/test.git
git remote -v

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