Git (持续更新)

一、命令解释:

git fetch origin master
git log -p master..origin/master
git merge origin/master
    以上命令的含义:
   首先从远程的originmaster主分支下载最新的版本到origin/master分支上
   然后比较本地的master分支和origin/master分支的差别
   最后进行合并
   上述过程其实可以用以下更清晰的方式来进行:

git fetch origin master:tmp
git diff tmp
git merge tmp

    从远程获取最新的版本到本地的test分支上
   之后再进行比较合并
2. git pull:相当于是从远程获取最新版本并merge到本地

git pull origin master

上述命令其实相当于git fetch git merge
在实际使用中,git fetch更安全一些
因为在merge前,我们可以查看更新情况,然后再决定是否合并

 

Git mergeno-ff可以保存你之前的分支历史。能够更好的查看merge历史,以及branch状态。

git merge 则不会显示 feature,只保留单条分支记录

删除本地分支

 $ git branch -D wanhugou/wanhutong-develop

 

2、情景用例:

Git拉取主版本中的最新代码到自己空间的分支

 

$ git fetch git@192.168.1.119:wanhugou/wanhutong.git develop

$ git checkout -b wanhugou/wanhutong-develop FETCH_HEAD

$ git checkout develop

$ git merge --no-ff wanhugou/wanhutong-develop

$ git push origin develop

$ git branch -D wanhugou/wanhutong-develop


 

异常:

出现这个异常说明“wanhugou/wanhutong-develop”这个分支已经存在,重新起一个不存在的分支名即可,如:


或者删除已存在的分支,命令如下:

$ git branch -D wanhugou/wanhutong-develop


签出远程分支,出现以下错误:

  1. fatal: Cannot update paths and switch to branch 'develop' at the same time.  
  2. Did you intend to checkout 'origin/develop' which can not be resolved as commit?
解决方法:

  1. $ git fetch  

$ git fetch git@192.168.1.119:wanhugou/wanhutong.git develop

冲突

如果系统中有一些配置文件在服务器上做了配置修改,然后后续开发又新添加一些配置项的时候,

在发布这个配置文件的时候,会发生代码冲突:

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撤销commit

1.命令:

a)git log

b)git reset --hard commit_id

2.打开git bash,并转到对应目录


3.执行命令:git log

记录由上至下出现的第二个commit_id(d1a65e9ac9a7c4396206f0072b7fbc9138a26c1f)


4.执行命令:git reset --hard commit_id

即:git reset --hard d1a65e9ac9a7c4396206f0072b7fbc9138a26c1f

5.再查看list.view.js和待push列表,即回到1.1和1.2的状态


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值