YY-LIN 发表于 2018-1-13 15:36:39

Git的日常处理流程

  前提:本地有2个分支,一个是master,还有一个是local
  master 默认追踪origin/master
  local 通过git branch -u origin/master来映射
  开发的时候,在local上,进行开发。master仅用于和remote进行同步
  备注:origin只是一个remote的名字而已,一个repository可以和多个remote进行关联
1.早上到公司后,进行代码同步,本地的commit暂时不需要push到服务器
  因为处于开发环境,所以,当前处于local分支
1.首先确认git status,确保本地的clean的状态
2.git fetch origin master:master
3.git status
   3.1如果提示告诉你,可以fast-forward
          3.1.1      git merge master
  这种情况,只在你本地没有commit的时候才发生
3.2 local 和master发生了diverged
  $ git status
  On branch local
  Your branch and 'origin/master' have diverged,
  and have 1 and 10 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)
  nothing to commit, working tree clean
      3.2.1    git rebase master
  $ git rebase master
  First, rewinding head to replay your work on top of it...
  Applying: local configuration
  如果遇到冲突的话,用TortoiseGit处理好,Mark文件为resolved。然后回到命令行,git rebase --continue
4.可以继续开发了
其中第2步,参考自
  https://stackoverflow.com/questions/18857570/git-pull-without-checkout
  git fetch <remote> <srcBranch>:<destBranch>
2.local 分支有一些*.config 文件进行了提交,之后,还有一些有效的需要push到服务器的commit
  当前处于local分支
1.git status确保clean状态
  $ git status
  On branch local
  nothing to commit, working tree clean
2.git checkout master
3.git pull
4.使用TortoiseGit进行cherry-pick,将local分支上有效的commit拿到master分支
5.git push
   5.1push失败
  在你pull之后,push之前,可能又有人往服务器push了新的commit
  处理方法,git fetch同步到最新的代码后,rebase origin/master。
  然后再次尝试push
6.使用TortoiseGit进行cherry-pick,将local分支上的config相关的commit拿到master分支上
7.使用TortoiseGit ,reset master 分支到origin/master
8.git checkout local
9.使用TortoiseGit,将local指向新生成的config的commit
10.可以继续开发了
11. remark
  上面使用的reset都是reset --hard,所以第一步的时候,需要确保git status是clean的状态
3.新的处理方式,和服务器进行代码交互
  前提,在local分支进行代码开发,master分支用来和服务器同步。当前处于local分支
3.1 git checkout master
3.2 git pull
3.3 使用TortoiseGit进行cherry-pick
3.4 git push
3.5 git rebase master local
  此步骤,最新的git for windows,已经可以自动跳过内容相同的commit。
  此命令的意思,以master作为base,然后把local上的代码拼接过去
  此命令,执行完成后,会自动切换到local
参考
  cherry-pick in TortoiseGit
注意
  因为涉及到local和master两个分支,所以在TortoiseGit查看日志的界面,务必勾选上左下角的All Branches。
  最好能仔细看完progit第三章,深入理解branch的概念,branch仅仅是一个指向commit的指针。
页: [1]
查看完整版本: Git的日常处理流程