git使用过程实记

***@***Latitude-5490:~/uos/src/uos_lidar_framework$ git status
On branch dev-brd-19q2
Your branch and 'origin/dev-brd-19q2' have diverged,
and have 2 and 1 different commit each, respectively.
  (use "git pull" to merge the remote branch into yours)
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	modified:   include/uos_lidar_framework/lidar_base.h

no changes added to commit (use "git add" and/or "git commit -a")
***@***-Latitude-5490:~/uos/src/uos_lidar_framework$ git pull
error: Your local changes to the following files would be overwritten by merge:
	include/uos_lidar_framework/lidar_base.h
Please, commit your changes or stash them before you can merge.
Aborting
***@***-Latitude-5490:~/uos/src/uos_lidar_framework$ git stash
Saved working directory and index state WIP on dev-brd-19q2: 874ddb7 Feature #16492: use '_' replace ' '
HEAD is now at 874ddb7 Feature #16492: use '_' replace ' '
***@***-Latitude-5490:~/uos/src/uos_lidar_framework$ git pull
Auto-merging include/uos_lidar_framework/lidar_base.h
CONFLICT (content): Merge conflict in include/uos_lidar_framework/lidar_base.h
Automatic merge failed; fix conflicts and then commit the result.
***@***-Latitude-5490:~/uos/src/uos_lidar_framework$ git stash pop
include/uos_lidar_framework/lidar_base.h: needs merge
unable to refresh index
***@***-Latitude-5490:~/uos/src/uos_lidar_framework$ git diff -w 
************************
***@***-Latitude-5490:~/uos/src/uos_lidar_framework$ git reset --hard
HEAD is now at 874ddb7 Feature #16492: use '_' replace ' '
***@***-Latitude-5490:~/uos/src/uos_lidar_framework$ git pull

Auto-merging include/uos_lidar_framework/lidar_base.h
CONFLICT (content): Merge conflict in include/uos_lidar_framework/lidar_base.h
Automatic merge failed; fix conflicts and then commit the result.
***@***-Latitude-5490:~/uos/src/uos_lidar_framework$ 
***@***-Latitude-5490:~/uos/src/uos_lidar_framework$ git fetch --all
Fetching origin
***@***-Latitude-5490:~/uos/src/uos_lidar_framework$ vim include/uos_lidar_framework/lidar_base.h 
***@***-Latitude-5490:~/uos/src/uos_lidar_framework$ git reset --hard dev-brd-19q2
HEAD is now at 874ddb7 Feature #16492: use '_' replace ' '
***@***-Latitude-5490:~/uos/src/uos_lidar_framework$ git fetch
***@***-Latitude-5490:~/uos/src/uos_lidar_framework$ git reset --soft HEAD^
***@***-Latitude-5490:~/uos/src/uos_lidar_framework$ git reset --soft HEAD^
***@***-Latitude-5490:~/uos/src/uos_lidar_framework$ git reset --hard HEAD^
***@***-Latitude-5490:~/uos/src/uos_lidar_framework$ git pull
***@***-Latitude-5490:~/uos/src/uos_lidar_framework$ git status

正常使用

碰到一个问题:之前应该是进行了git reset 的操作,导致别人提交的部分文件被我一起git commit 和git push到远程端了,为解决该问题,将别人的提交去掉,保留自己的提交

1)如果已经进行git commit 和git push,到gerrit上查找该最新提交的commit编号
2)如果只进行git commit 没有进行git push,在git log里找到对应的commit 编号
建立分支:

git branch commit编号                   // 注意commit和编号之间没有空格

2.git status

出现如下

Your branch and 'origin' have diverged,
and have 1 and 1 different commit each, respectively.
  (use "git pull" to merge the remote branch into yours)
nothing to commit, working directory clean

3.`git reset --hard HEAD^^

git pull

git cherry-pick 编号

git log
4.

git status

出现如下:

Your branch is ahead of 'origin' by 1 commit.
  (use "git push" to publish your local commits)
nothing to commit, working directory clean
git reset HEAD^
出现如下:
Unstaged changes after reset:
M     你修改的文件路径

6.git status
出现正常的情况
7.git reset --hard HEAD (到最新版)
8.giit cherry-pick 编号  (该条命令如上)
9.git push

即可

参考链接:
https://blog.csdn.net/u011240877/article/details/52668807
https://blog.csdn.net/luoww1/article/details/70213627
https://www.jianshu.com/p/d969fee31c13
commit之后,想撤销commit:https://www.cnblogs.com/lfxiao/p/9378763.html
https://www.cnblogs.com/zndxall/archive/2018/09/04/9586088.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值