git 相關命令

一、安裝gitphp

二、設置用戶名和emailgit

       git config --global user.name 「用戶名」github

 

       git config --global user.email 「郵箱」npm

三、生成key 執行生成公鑰和私鑰的命令:ssh-keygen -t rsa 並按回車3下app

四、cat ~/.ssh/id_rsa.pub  將公鑰添加到github,或者gitlab的  Deploy Keys 中ssh

 

----------------------------------------------------------------------------------------------------------------------------------------gitlab

一、獲取遠程分支到本地spa

    git checkout -b cmsm-v0.0.1 origin/cmsm-v0.0.1debug

二、提交本地分支到遠程倉庫code

  git push origin cmsm-v0.0.1:cmsm-v0.0.1

三、提交本地  v1分支到遠程v1分支 

       git push orgin v1

四、更新遠程 v1分支到本地v1分支

      git pull orgin v1

五、刪除遠程分支

      git push orgin --delete v3

六、 刪除本地分支

     git branch -d v3

 

----------------------------------------------------------------------------------------------------------------------------

1、保存成都分支和成都new分支的差異.
Administrator@USER-20161116WV MINGW64 /d/demo/gitproject/front (cmsm-for-chengdu)
$ git diff cmsm-for-chengdu-new >./diff.path

Administrator@USER-20161116WV MINGW64 /d/demo/gitproject/front (cmsm-for-chengdu)
$ ls
CentralizedMfront/  CMSystemNW/  diff.path  flashPlayer/  npm-debug.log  nwjs-win-x64/

Administrator@USER-20161116WV MINGW64 /d/demo/gitproject/front (cmsm-for-chengdu)
$ vi diff.path

2、切換到成都new分支並應用這些差異
Administrator@USER-20161116WV MINGW64 /d/demo/gitproject/front (cmsm-for-chengdu)
$ git checkout cmsm-for-chengdu-new
gSwitched to branch 'cmsm-for-chengdu-new'
i
Administrator@USER-20161116WV MINGW64 /d/demo/gitproject/front (cmsm-for-chengdu-new)
$ git apply --reject --whitespace=fix diff.path

3、則成都new分支和成都分支則無差異
4、此時,merge 成都分支的話,才能夠 push當前分支到成都分支
Administrator@USER-20161116WV MINGW64 /d/demo/gitproject/front (cmsm-for-chengdu-new)
$ git merge cmsm-for-chengdu
Already up-to-date.

Administrator@USER-20161116WV MINGW64 /d/demo/gitproject/front (cmsm-for-chengdu-new)
$ git rm CMSystemNW/picture/bg.png^C

Administrator@USER-20161116WV MINGW64 /d/demo/gitproject/front (cmsm-for-chengdu-new)
$ git push origin cmsm-for-chengdu-new:cmsm-for-chengdu

 

git cherry-pick用於把另外一個本地分支的commit修改應用到當前分支。
實際問題 
  在本地 master 分支上作了一個commit ( 38361a68138140827b31b72f8bbfd88b3705d77a ) , 如何把它放到 本地 old_cc 分支上? 
辦法之一: 使用 cherry-pick.  根據git 文檔:
Apply the changes introduced by some existing commits 
就是對已經存在的commit 進行apply (能夠理解爲再次提交)
簡單用法:
git cherry-pick <commit id>
例如:
$ git checkout old_cc
$ git cherry-pick 38361a68
1. 若是順利,就會正常提交。結果:
Finished one cherry-pick.
# On branch old_cc
# Your branch is ahead of 'origin/old_cc' by 3 commits.
2. 若是在cherry-pick 的過程當中出現了衝突
Automatic cherry-pick failed.  After resolving the conflicts,
mark the corrected paths with 'git add <paths>' or 'git rm <paths>'
and commit the result with: 
 
        git commit -c 15a2b6c61927e5aed6718de89ad9dafba939a90b
 
就跟普通的衝突同樣,手工解決:
執行git status 看哪些文件出現衝突
$ git status 
both modified:      app/models/user.rb 
接着手動解決衝突的文件,而後經過git add把改到添加到索引,最後執行git commit提交修改就行了。

 

  Add 回退的方法:

git add app/controllers/cart_controller.php git stash --keep-index git reset

查看 文件修改的記錄

1、查看某個文件的提交記錄
git log -- filename (git log filename)
2、能夠顯示該文件每次提交的diff
git log -p filename

3. 查看某次提交中的某個文件變化
git show commit-id filename

4.根據commit-id查看某個提交

git show commit-id
 
 

 

1.使用git log -g 找回以前提交的commit

2.使用git branch recover_branch[新分支] commit_id命令用這個commit建立一個分支

此時 recover_branch is your delete branch.
相關文章
相關標籤/搜索