***@***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