git的一些經常使用命令

1.經常使用命令
git add
git commit -m "xxxxx"
git pull/push
 
2.假如git pull的時候有衝突呢:
Password for 'https://huangliang@git.blizzmi.com':
Updating 1290bd5..ea71164
error: Your local changes to the following files would be overwritten by merge:
slot_server/apps/slot_server/src/lib/lib_mnesia.erl
Please, commit your changes or stash them before you can merge.
 
意思是我臺式機上新修改的代碼的文件,將會被git服務器上的代碼覆蓋;我固然不想剛剛寫的代碼被覆蓋掉,看了git的手冊,發現能夠這樣解決:
 
方法1:若是你想保留剛纔本地修改的代碼,並把git服務器上的代碼pull到本地(本地剛纔修改的代碼將會被暫時封存起來)
git stash git pull origin master git stash pop
 
如此一來,服務器上的代碼更新到了本地,並且你本地修改的代碼也沒有被覆蓋,以後使用add,commit,push 命令便可更新本地代碼到服務器了。
 
方法二、若是你想徹底地覆蓋本地的代碼,只保留服務器端代碼,則直接回退到上一個版本,再進行pull:
git reset --hard git pull origin master
 
注:其中origin master表示git的主分支。
 
 
git stash 先存儲本身的
 
git pull origin master 從master上拉取最新代碼
 
git stash pop 把本身本地的代碼和更新的代碼,合併
 
git add ./ 當前文件夾
 
git status 查看狀態
 
git --help
 
提交文件
git add ./
git commit -m "xxx"
git push
 
查看狀態
git status
 
撤銷,回退當前狀態
git reset
 
查看當前分支
git branch -a
 
切換分支
git checkout master
 
切換分支,而且更新其餘分支的代碼到該分支
git checkout newconfig_slot_server
git pull origin develop
 
新建develop分支
git checkout -b dev 本地倉庫切換和建立新分支
git branch 查看分支
git push --set-upstream origin dev 提交分支到遠程倉庫
 
本地拉取分支
git checkout -b develop origin/develop
 
刪除本地分支
git branch -D dev_1
刪除本地tag
git tag -d tag_v0.1.0
 
刪除遠程分支
git push origin :branch-name 刪除遠程倉庫
 
git branch -r -d origin/branch-name 只針對本地的遠程倉庫
 
強制覆蓋本地文件
git reset --hard origin/develop
git pull
 
正確的作法應該是
git fetch --all git reset --hard origin/develop
 
撤銷add
git reset
 
咱們拿 README.md 這個文件舉例,好比修改了一段文字描述,想恢復回原來的樣子:
git restore README.md
便可,若是修改已經被 git add README.md 放入暫存隊列,那就要
git unstage README.md
git restore README.md
 
 
撤銷commit
git reflog
找到須要回退的那次commit的 哈希值,
git reset --hard commit_id 
 
撤銷修改
(use "git checkout -- <file>..." to discard changes in working directory)
 
建立輕量標籤tag
$ git tag v0.1.2
$ git push origin v0.1.2 # 將v0.1.2標籤提交到git服務器
$ git push origin --tags # 將本地全部標籤一次性提交到git服務器
 
 
加入不提交隊列
git update-index --assume-unchanged apps/slot_lib/src/pb_messages.erl
取消加入不提交隊列
git update-index --no-assume-unchanged apps/slot_lib/src/proto/
 
2、拉取遠程分支並建立本地分支
方法一
使用以下命令:
git checkout -b 本地分支名x origin/遠程分支名x
  • 1
  • 1
使用該方式會在本地新建分支x,並自動切換到該本地分支x。
方式二
使用以下命令:
git fetch origin 遠程分支名x:本地分支名x
  • 1
  • 1
使用該方式會在本地新建分支x,可是不會自動切換到該本地分支x,須要手動checkout。
 
 
 
 
 
linux命令行:如何提交上github(貌似必須先上網站建立倉庫,後續才能用命令)
先到www.github.com網站上create new repository
而後根據提示操做:
…or create a new repository on the command line
echo "# pb_msgcodegen" >> README.md git init git add README.md git commit -m "first commit" git remote add origin https://github.com/huang2287832/pb_msgcodegen.git git push -u origin master
 
…or push an existing repository from the command line
git remote add origin https://github.com/huang2287832/pb_msgcodegen.git git push -u origin master
 
 
若是系統中有一些配置文件在服務器上作了配置修改,而後後續開發又新添加一些配置項的時候,
在發佈這個配置文件的時候,會發生代碼衝突:
error: Your local changes to the following files would be overwritten by merge:
        protected/config/main.php
Please, commit your changes or stash them before you can merge.
若是但願保留生產服務器上所作的改動,僅僅併入新配置項, 處理方法以下:
git stash git pull git stash pop
而後可使用 Git diff -w +文件名 來確認代碼自動合併的狀況.
 
反過來,若是但願用代碼庫中的文件徹底覆蓋本地工做版本. 方法以下:
git reset --hard git pull
其中 git reset是針對版本,若是想針對文件回退本地修改,使用
[plain]  view plain  copy
  1. git checkout HEAD file/to/restore  
 
 
請求合併分支:
 
 
合併分支:
 
git checkout master
 
git pull
 
git merge develop
 
git push
 
而後刪除遠程分支:
 
git push origin :develop 刪除遠程分支
 
git branch -D dev_1 刪除本地分支
 
開發新內容:
git checkout -b dev _1 從新拉分支
 
從新建develop分支
git checkout -b dev 本地倉庫切換和建立新分支
git branch -a 查看分支
git push --set-upstream origin dev 提交分支到遠程倉庫
git branch -a
 
解決衝突神器:
git fetch origin develop 先把遠程develop拉到本地
而後再說使用develop
git checkout origin/develop -- apps/slot_server/src/pp/pp_slot.erl
相關文章
相關標籤/搜索