零、git常用命令
1.切换到master分支
git checkout master
git pull
2.从当前分支(master)复制一份作为开发分支
git checkout -b dev_x.x.x
3.将开发分支同步到远程
git push origin dev_x.x.x
4.关联本地分支和远程分支
git branch --set-upstream-to=origin/dev_x.x.x
git pull
5.强制拉取远程分支并覆盖本地分支
git fetch --all
git reset --hard origin/dev_x.x.x
一、git提交仓库后,修改本地代码后重新提交
1.背景
Modify CVE-2022-4144 · Pull Request !394 · openEuler/qemu - Gitee.com
我提交了关于qemu的代码pr,可是审查有修改意见,要去掉[PATCH */5]这样的标题并调整5个patch的顺序,需要自己重新rebase 修改后提交
2.主要步骤总结
设置好自己的远程fork的qemu仓库(本步骤可略过)
git log --pretty=oneline 查看日志,找到要rebase -i 的节点id
git rebase -i 7cb2d342bxxxxxxxxx 变基修改,包括commit的信息、调整顺序
git log --pretty=oneline 再次查看日志,确认是否修改成功
git push -f origin qemu-6.2.0 (强制)push到远程仓库
3.详细步骤
JCF@DESKTOP-K6DF0BR MINGW64 /e/Git/qemu/qemu (qemu-6.2.0)
$ git remote -v
origin git@gitee.com:jianchunfu/qemu.git (fetch)
origin git@gitee.com:jianchunfu/qemu.git (push)
upstream git@gitee.com:jianchunfu/qemu.git (fetch)
upstream git@gitee.com:jianchunfu/qemu.git (push)
JCF@DESKTOP-K6DF0BR MINGW64 /e/Git/qemu/qemu (qemu-6.2.0)
$ git config --global --list
user.name=jianchunfu
user.email=jianchunfu_yewu@cmss.chinamobile.com
JCF@DESKTOP-K6DF0BR MINGW64 /e/Git/qemu/qemu (qemu-6.2.0)
$ ssh -T git@gitee.com
Hi jianchunfu! You've successfully authenticated, but GITEE.COM does not provide shell access.
JCF@DESKTOP-K6DF0BR MINGW64 /e/Git/qemu/qemu (qemu-6.2.0)
$ git remote remove upstream
JCF@DESKTOP-K6DF0BR MINGW64 /e/Git/qemu/qemu (qemu-6.2.0)
$ git remote -v
origin git@gitee.com:jianchunfu/qemu.git (fetch)
origin git@gitee.com:jianchunfu/qemu.git (push)
JCF@DESKTOP-K6DF0BR MINGW64 /e/Git/qemu/qemu (qemu-6.2.0)
$ git remote add upstream https://gitee.com/jianchunfu/qemu.git /*将原来的git链接转为http链接。。不改应该也没事*/
JCF@DESKTOP-K6DF0BR MINGW64 /e/Git/qemu/qemu (qemu-6.2.0)
$ git remote -v
origin git@gitee.com:jianchunfu/qemu.git (fetch)
origin git@gitee.com:jianchunfu/qemu.git (push)
upstream https://gitee.com/jianchunfu/qemu.git (fetch)
upstream https://gitee.com/jianchunfu/qemu.git (push)
JCF@DESKTOP-K6DF0BR MINGW64 /e/Git/qemu/qemu (qemu-6.2.0)
$ git remote set-url --push upstream no_push /*避免误推送*/
JCF@DESKTOP-K6DF0BR MINGW64 /e/Git/qemu/qemu (qemu-6.2.0)
$ git remote -v
origin git@gitee.com:jianchunfu/qemu.git (fetch)
origin git@gitee.com:jianchunfu/qemu.git (push)
upstream https://gitee.com/jianchunfu/qemu.git (fetch)
upstream no_push (push)
----------------------------------------------------------------------------------------
JCF@DESKTOP-K6DF0BR MINGW64 /e/Git/qemu/qemu (qemu-6.2.0)
$ git fetch upstream
From https://gitee.com/jianchunfu/qemu
* [new branch] master -> upstream/master
* [new branch] openEuler-20.03-LTS -> upstream/openEuler-20.03-LTS
* [new branch] openEuler-20.03-LTS-Next -> upstream/openEuler-20.03-LTS-Next
* [new branch] openEuler-20.03-LTS-SP1 -> upstream/openEuler-20.03-LTS-SP1
* [new branch] qemu-5.0.0-dpu -> upstream/qemu-5.0.0-dpu
* [new branch] qemu-6.2.0 -> upstream/qemu-6.2.0
……
JCF@DESKTOP-K6DF0BR MINGW64 /e/Git/qemu/qemu (qemu-6.2.0)
$ git checkout master
Updating files: 100% (3028/3028), done.
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
JCF@DESKTOP-K6DF0BR MINGW64 /e/Git/qemu/qemu (master)
$ git rebase upstream/master
Current branch master is up to date.
----------------------------------------------------------------------------------------
JCF@DESKTOP-K6DF0BR MINGW64 /e/Git/qemu/qemu (master)
$ git branch
* master
qemu-6.2.0
JCF@DESKTOP-K6DF0BR MINGW64 /e/Git/qemu/qemu (master)
$ git checkout qemu-6.2.0
Updating files: 100% (3028/3028), done.
Switched to branch 'qemu-6.2.0'
Your branch is up to date with 'origin/qemu-6.2.0'.
JCF@DESKTOP-K6DF0BR MINGW64 /e/Git/qemu/qemu (qemu-6.2.0)
$ git log --pretty=oneline
c2b2aa2441a3654b68ee56a319fe7d2145761836 (HEAD -> qemu-6.2.0, upstream/qemu-6.2.0, origin/qemu-6.2.0) [PATCH 5/5] target/ppc: exit(1) on failure in kvmppc_get_clockfreq()
842b4a2a7c8531cfb36a9cba1ba4ab078956b329 [PATCH 4/5] target/ppc: use g_autofree in kvmppc_read_int_cpu_dt()
b8fda105d4f0719feb02e5d9b2151214ef3b77e7 [PATCH 3/5] target/ppc: Add error reporting when opening file fails
c0225fd4eef1437c25a7ec10572600b091bc8c0d [PATCH 2/5] target/ppc: add errp to kvmppc_read_int_cpu_dt()
614c371bcc2dfa00a5ca6f7f6076006f86dcaa25 [PATCH 1/5]target/ppc/kvm.c: do not return -1 on uint64_t return
7cb2d342b9073ec9548202df6e1fb25fa4997d71 migration/dirtyrate: Replace malloc with g_new Using macro g_new() to handling potential memory allocation failures in dirtyrate.
79316f6f933cbff63a6bdb54032696a23e88b2d0 !317 hw/vhost-user-blk: turn on VIRTIO_BLK_F_SIZE_MAX feature for virtio blk device From: @taoziyaoyao Reviewed-by: @aven6 Signed-off-by: @yezengruan
JCF@DESKTOP-K6DF0BR MINGW64 /e/Git/qemu/qemu (qemu-6.2.0)
$ git rebase -i 7cb2d342b9073ec9548202df6e1fb25fa4997d71
[detached HEAD 6ad4a6b469] target/ppc/kvm.c: do not return -1 on uint64_t return
Date: Mon Aug 1 01:23:12 2022 +0000
1 file changed, 2 insertions(+), 2 deletions(-)
[detached HEAD 9da3aade1a] target/ppc: add errp to kvmppc_read_int_cpu_dt()
Date: Mon Aug 1 01:29:56 2022 +0000
1 file changed, 9 insertions(+), 7 deletions(-)
[detached HEAD c8e2b5071c] target/ppc: Add error reporting when opening file fails
Date: Mon Aug 1 01:36:03 2022 +0000
1 file changed, 3 insertions(+), 2 deletions(-)
[detached HEAD e330bdb2b3] target/ppc: use g_autofree in kvmppc_read_int_cpu_dt()
Date: Mon Aug 1 01:39:16 2022 +0000
1 file changed, 3 insertions(+), 5 deletions(-)
[detached HEAD 0a02e76997] target/ppc: exit(1) on failure in kvmppc_get_clockfreq()
Date: Mon Aug 1 01:42:53 2022 +0000
1 file changed, 16 insertions(+), 1 deletion(-)
Successfully rebased and updated refs/heads/qemu-6.2.0.
JCF@DESKTOP-K6DF0BR MINGW64 /e/Git/qemu/qemu (qemu-6.2.0)
$ git log --pretty=oneline
0a02e769973f103f478da6010d7f681ae9241446 (HEAD -> qemu-6.2.0) target/ppc: exit(1) on failure in kvmppc_get_clockfreq()
e330bdb2b3023f9ee38cc03379255d45dafe346c target/ppc: use g_autofree in kvmppc_read_int_cpu_dt()
c8e2b5071cceaff460d368eaf5284e41a84d06f7 target/ppc: Add error reporting when opening file fails
9da3aade1ab605ece0d111c84d61e5e9f290a9cb target/ppc: add errp to kvmppc_read_int_cpu_dt()
6ad4a6b469be497d5d89085ad8b2de2e4eae5c36 target/ppc/kvm.c: do not return -1 on uint64_t return
7cb2d342b9073ec9548202df6e1fb25fa4997d71 migration/dirtyrate: Replace malloc with g_new Using macro g_new() to handling potential memory allocation failures in dirtyrate.
79316f6f933cbff63a6bdb54032696a23e88b2d0 !317 hw/vhost-user-blk: turn on VIRTIO_BLK_F_SIZE_MAX feature for virtio blk device From: @taoziyaoyao Reviewed-by: @aven6 Signed-off-by: @yezengruan
JCF@DESKTOP-K6DF0BR MINGW64 /e/Git/qemu/qemu (qemu-6.2.0)
$ git remote -v
origin git@gitee.com:jianchunfu/qemu.git (fetch)
origin git@gitee.com:jianchunfu/qemu.git (push)
upstream https://gitee.com/jianchunfu/qemu.git (fetch)
upstream no_push (push)
JCF@DESKTOP-K6DF0BR MINGW64 /e/Git/qemu/qemu (qemu-6.2.0)
$ git branch
master
* qemu-6.2.0
JCF@DESKTOP-K6DF0BR MINGW64 /e/Git/qemu/qemu (qemu-6.2.0)
$ git push -f origin qemu-6.2.0 /*push的远端仓库为origin而不是upstream,按理说两者一样,但官方手册是origin(https://gitee.com/openeuler/community/blob/master/zh/contributors/Gitee-workflow.md)*/
Enumerating objects: 29, done.
Counting objects: 100% (29/29), done.
Delta compression using up to 12 threads
Compressing objects: 100% (9/9), done.
Writing objects: 100% (25/25), 2.57 KiB | 1.28 MiB/s, done.
Total 25 (delta 20), reused 16 (delta 16), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.3]
To gitee.com:jianchunfu/qemu.git
+ c2b2aa2441...0a02e76997 qemu-6.2.0 -> qemu-6.2.0 (forced update)
二、git提交仓库后,远程仓库中途变动导致之前的提交被冲突
1.背景Add support for the ppc64le platform. · Pull Request !845 · src-openEuler/qemu - Gitee.com
我先提交了关于qemu的改动,但在合入审查期间,别人提的pr却率先合入到qemu,导致我之前的提交被冲突,所以需要修改后重提。
2.主要步骤总结
git remote add 欧拉的src-qemu
git checkout 我的提交分支
git pull rebase 欧拉的src-qemu/master
vim 解决冲突
git push 我自己的远程fork仓库master分支
3.详细步骤记录
jcf00637@HX02040125 MINGW64 /d/Git/src-qemu (master)
$ git remote -v
origin https://gitee.com/jianchunfu/src-qemu.git (fetch)
origin https://gitee.com/jianchunfu/src-qemu.git (push)
jcf00637@HX02040125 MINGW64 /d/Git/src-qemu (master)
$ git remote add oe https://gitee.com/src-openeuler/qemu.git /*远程仓库添加上src-openeuler/qemu主社区*/
jcf00637@HX02040125 MINGW64 /d/Git/src-qemu (master)
$ git remote -v
oe https://gitee.com/src-openeuler/qemu.git (fetch)
oe https://gitee.com/src-openeuler/qemu.git (push)
origin https://gitee.com/jianchunfu/src-qemu.git (fetch)
origin https://gitee.com/jianchunfu/src-qemu.git (push)
jcf00637@HX02040125 MINGW64 /d/Git/src-qemu (master)
$ git branch
* master
jcf00637@HX02040125 MINGW64 /d/Git/src-qemu (master)
$ git pull --rebase oe master /*从src-openeuler/qemu主社区变基并回合到本地master分支*/
remote: Enumerating objects: 192, done.
remote: Counting objects: 100% (192/192), done.
remote: Compressing objects: 100% (162/162), done.
remote: Total 190 (delta 28), reused 189 (delta 28), pack-reused 0
Receiving objects: 100% (190/190), 257.85 KiB | 546.00 KiB/s, done.
Resolving deltas: 100% (28/28), completed with 2 local objects.
From https://gitee.com/src-openeuler/qemu
* branch master -> FETCH_HEAD
* [new branch] master -> oe/master
error: could not apply de4dc58... spec: Add support for the ppc64le platform
Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".
Could not apply de4dc58... spec: Add support for the ppc64le platform
Auto-merging qemu.spec
CONFLICT (content): Merge conflict in qemu.spec
jcf00637@HX02040125 MINGW64 /d/Git/src-qemu (master|REBASE 1/1)
$ vim qemu.spec /*手动解决冲突,主要是vim修改>>>>>>>和=====之间不一样的地方*/
jcf00637@HX02040125 MINGW64 /d/Git/src-qemu (master|REBASE 1/1)
$ git add qemu.spec /*按提示先添加add*/
jcf00637@HX02040125 MINGW64 /d/Git/src-qemu (master|REBASE 1/1)
$ git rebase --continue /*rebase成功*/
[detached HEAD 95d9ef9] spec: Add support for the ppc64le platform
1 file changed, 31 insertions(+), 3 deletions(-)
Successfully rebased and updated refs/heads/master.
jcf00637@HX02040125 MINGW64 /d/Git/src-qemu (master)
$ git status
On branch master
Your branch and 'origin/master' have diverged,
and have 3 and 1 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
nothing to commit, working tree clean
jcf00637@HX02040125 MINGW64 /d/Git/src-qemu (master)
$ git log --pretty=oneline /*log发现已经是理想状态 */
95d9ef98ff9bb6f92511eab25e0bcd62af87af3f (HEAD -> master) spec: Add support for the ppc64le platform
037bfea747df2b94e74faf8c3714a209db9673b9 (oe/master) !846 QEMU update to version 6.2.0-84(master)
946c69b8875ed50024bc4bab1bed8c4c0cac2ac3 QEMU update to version 6.2.0-84(master) - hw/arm/fsl-imx: ……
24ecabf224b23a65b7d07b4b9aada908b63a3080 !836 QEMU update to version 6.2.0-83(master)
80a22cff3762f945e9d4ce5165eb9d83eaa8a436 QEMU update to version 6.2.0-83(master) - hw/virtio/virtio-pmem: ……
jcf00637@HX02040125 MINGW64 /d/Git/src-qemu (master)
$ git remote -v
oe https://gitee.com/src-openeuler/qemu.git (fetch)
oe https://gitee.com/src-openeuler/qemu.git (push)
origin https://gitee.com/jianchunfu/src-qemu.git (fetch)
origin https://gitee.com/jianchunfu/src-qemu.git (push)
jcf00637@HX02040125 MINGW64 /d/Git/src-qemu (master)
$ git push origin master
To https://gitee.com/jianchunfu/src-qemu.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://gitee.com/jianchunfu/src-qemu.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
jcf00637@HX02040125 MINGW64 /d/Git/src-qemu (master)
$ git push -f origin master /*因为本地和远程不一致,所以只能强推,强制远程fork的仓库变成本地的样子*/
Enumerating objects: 195, done.
Counting objects: 100% (195/195), done.
Delta compression using up to 16 threads
Compressing objects: 100% (165/165), done.
Writing objects: 100% (193/193), 273.24 KiB | 30.36 MiB/s, done.
Total 193 (delta 30), reused 190 (delta 28), pack-reused 0
remote: Resolving deltas: 100% (30/30), completed with 2 local objects.
remote: Powered by GITEE.COM [GNK-6.4]
To https://gitee.com/jianchunfu/src-qemu.git
+ de4dc58...95d9ef9 master -> master (forced update)