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.
相关文章
相关标签/搜索