【GIT】git 错误记录

目录

error: Your local changes to the following files would be overwritten by merge: xxx/...

git error:the following untracked working tree files would be overwritten by merge

git 出现分支游离问题 You are in 'detached HEAD' state

git命令提交后push失败,缺少changeID的解决办法

git cherry-pick

 git cherry pick 后 push remote reject、git push 时【remote rejected】 error: 无法推送一些引用到 'xxx'

git cherry-pick xxx  fatal: bad object xxx

Git push error: does not match your user account

no new changes [remote rejected] HEAD -> refs/for/dev (no new changes)

gerrit merge后不能提交问题

报错commit is a merge but no -m option was given.

Git push remote rejected {change ### closed}

linux git patch 和patch以及git diff 命令

commit subject >65 characters; use shorter first paragraph

too many commit message lines longer than 70 characters

解决git cherry-pick 出现bad version 

git cherry-pick 出现bad version


error: Your local changes to the following files would be overwritten by merge: xxx/...

Git出现冲突error: Your local changes to the following files would be overwritten by merge: xxx/... - 简书

git error:the following untracked working tree files would be overwritten by merge

git error:the following untracked working tree files would be overwritten by merge_山中有石为玉-CSDN博客

git 出现分支游离问题 You are in 'detached HEAD' state

git 提示 detached head 解决办法_clk863399393的博客-CSDN博客

参考链接
* detached head是一种HEAD指针指向了某一个具体的 commit id,而不是分支的情况。在这个状态下进行的commit不会对你的远程分支产生影响

出现的原因

  1. 从远程库clone下来一个远程的repository
  2. clone下来之后,git自动在本地建立了一个本地分支master,并自动与远程库master关联
  3. 现在再操作checkout其他分支名(分支a)
    • 因为本地的工作区目前是刚刚clone的master分支的代码并且与远程关联,但是本机上没有本地分支与远程[分支a]关联,所以checkout一下就会出现detached head的状态(直接指向了commit id,因为git是离线版本控制,因为此checkout是远程的不是本地的,所以git只能给你一个commit id让你进行操作)

解决办法

  • checkout 的时候如果本地没有与之关联,则在命令加上参数在本地新建分支并与之对应即可
  • git checkout -b new_branch_name

git命令提交后push失败,缺少changeID的解决办法

如果是log的最顶端那条没有changeID 一般按提示的命令操作即可:

gitdir=$(git rev-parse --git-dir); scp -p -P 29418 ****@*******:hooks/commit-msg ${gitdir}/hooks/

git commit --amend --no-edit

如果不是最顶端的那条没有changeID 则:

方法一:

先 git reset --soft   ****ddfd  (恢复到最近的(即最顶的)那条没有change-id的提交记录),重新提交$ git commit -am "提交信息" 重新提交修改记录 

如果是多条的,则重复上面的 git reset --soft   xxxxx  +  git commit -am "提交信息" 直到所有的都有changeID

然后git push ……

方法二:

push失败后,下面会有失败原因和处理方法提示,先按它的提示处理。

实在不行在参考下面的:

第一步,找到缺失 Change-Id 的那个 commit:

如果缺少Change-Id的commit 不是上一条,如git log中的倒数第4条(commit为:d714bcde0c14ba4622d28952c4b2a80882b19927)

第二步,编辑交互式 rebase 的命令文件:

git rebase -i HEAD~4

$ git rebase -i d714bcde0c14ba4622d28952c4b2a80882b19927

这个命令会打开默认的编辑器,一般为 vi. 内容如下:

pick 1a9096a I am commit message 1
pick 8e1cad3 I am commit message 2
pick 8aaaa74 I am commit message 3
# Rebase d714bcd..8aaaa74 onto d714bcd
#
……

可以将这个文件理解为 git rebase 的内嵌脚本.其命令写法已经在下面的注释里给出了.

这里不赘述,仅给出最终要将该文件编辑成什么样子:

reword 1a9096a I am commit message 1
pick 8e1cad3 I am commit message 2
pick 8aaaa74 I am commit message 3
# Rebase d714bcd..8aaaa74 onto d714bcd
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
……
  • 即: 将缺失了 Change-Id 的 commit 前面的 "pick" 改为 "reword" 即可. 保存退出 (:wq)
  • 注1: 上述文件中 commit 的顺序是和 git log 显示的顺序相反的: git log 为最新的在最前; 上述文件为 最新的在最后.
  • 注2: 如果进入该模式后,却不确定该怎么改,这时不要担心,直接退出编辑则什么都不会发生 (:q!)
  • 注3: 如果没有搞清楚运作机制,就要注意,除了按需把 pick 改为 reword 外,不要做其他改动.尤其注意不要删除任何行 (被删除的那行对应的提交将丢失).
  • 注4: 你应该已经发现,有多个 commit 缺失 Change-Id 的情况也可以用该方法一次性处理.

第三步,逐个编辑 commit-msg:

上一步打开的文件保存退出后,git会逐个打开被你标注了 reword 的提交日志页面.

不需要修改任何东西,逐个保存退出即可 (一路 :wq).

第四步,再次提交:

用 git log 查看提交日志,会发现缺失的 Change-Id 都生成了. 愉快的提交代码吧!

$ git push review HEAD:refs/for/develop

[gerrit场景教程] gerrit "missing Change-Id"解决办法_谦虚使人发胖的博客-CSDN博客

对于merge产生的commit,git rebase 需要加--preserve-merges 才能看到

you can use

git rebase -i --preserve-merges

or

git checkout -b temp SHA1-of-merge
git commit --amend # this is where you change your message
git rebase --onto temp SHA1-of-merge my-branch

请记住,在这之后你需要强制推送你的分支,并且可能需要告诉目前在 repo 上工作的任何人。

version control - Git merge & adding change id - Stack Overflow

git cherry-pick

 git cherry pick 后 push remote reject、git push 时【remote rejected】 error: 无法推送一些引用到 'xxx'

git cherry pick 了其他分支(已关闭)的commit后提交出现此报错。

解决方法是:

git reset --soft   cherry pick下面的commit的 前一个commit 的id

然后重新commit

git commit -m “xxxxx”

最后push

其他解决方法:

Git push remote rejected {change ### closed} - 加个小鸡腿 - 博客园

fatal: bad revision '121bc2d1236' fatal: bad revision '121bc2d1236'_thlzjfefe的博客-CSDN博客

原因是本地没有A分支的代码,应先拉取该分支的代码,步骤如下:

1、git fetch --all

2、git cherry-pick 121bc2d1236

3、git push

git cherry-pick xxx  fatal: bad object xxx

摘抄:“我没有切到B分支pull一下。总结过来就是git cherry-pick是本地特性,本地要有这个commit才可以被git cherry-pick”。

git cherry-pick 的时候出现git cherry-pick xxx  fatal: bad object xxx_默一鸣的博客-CSDN博客

意思应该是说,A commit后还没有push 上去,还在 A分支本地,所以在A的文件夹切换到B,然后git cherry-pick?

或者在A push 上去,然后git fetch --all  + git cherry-pick 121bc2d1236

Git push error: does not match your user account

remote: ERROR:  In commit b6b74fff7850c4b61a5535519959b1ab58ca6fa9
remote: ERROR:  committer email address aaa@aaa
remote: ERROR:  does not match your user account.
remote: ERROR:
remote: ERROR:  The following addresses are currently registered:
remote: ERROR:    bbb@bbb
remote: ERROR:
remote: ERROR:  To register an email address, please visit:
remote: ERROR:  http://xxxxxxxx

You can run these commands:

git config --global user.name "Your Name"
git config --global user.email you@example.com

Then run this to edit the commit to reset the author:

git commit --amend --reset-author

 gerrit - Git push error: does not match your user account - Stack Overflow

amend命令只会修改最后一次commit的信息,之前的commit(或批量)需要使用rebase:

$ git rebase -i HEAD~3
 
# 输出如下
pick 1 commit 1
pick 2 commit 2
pick 3 commit 3

要修改哪个,就把那行的pick改为edit,然后退出。例如想修改commit 1的author,光标移到第一个pick,按i键进入INSERT模式,把pick改为edit:

edit 1 commit 1
pick 2 commit 2
pick 3 commit 3
...
-- INSERT -- 

然后按esc键,退出INSERT模式,输入:wq退出,这时可以看到提示,可以修改commit 1的信息了:

Stopped at 1 commit 1
You can amend the commit now, with
    git commit --amend
Once you are satisfied with tour changes, run
    git rebase --continue 

输入amend命令重置用户信息:

$ git commit --amend --reset-author

会出现commit 1的提交记录及注释内容,可进入INSERT模式修改注释,:wq退出。这时再查看提交历史,发现commit 1的author已经变成b(b@email.com)了,且是最新一次记录。

通过continue命令回到正常状态:

$ git rebase --continue

不断重复,直至完成
原文链接:https://blog.csdn.net/mocoe/article/details/84344411

no new changes [remote rejected] HEAD -> refs/for/dev (no new changes)

问题:使用 git merge 在本地执行分支合并操作,然后想 push 到 gerrit 上评审入库,可是在提交时,提示:

 ! [remote rejected] HEAD -> refs/for/dev (no new changes)

分析:no new changes 的意思,是说,这个合并,是个线性的合并。而合并的那些历史的 commit 节点,在 gerrit 上都已经评审过了,都是已有的 change 单,所以 gerrit 认为没有新的提交,就不让你提交评审。

方法1: 在 git merge 的时候,加上 --no-ff 参数,是为了让它生成一个新的 commit,这样就可以提交了~(不过生成的 gerrit change 是看不到改动信息的)

方法2:不经过 gerrit,直接 push 入远程库。(不推荐)

原文链接:https://blog.csdn.net/Frankltf/article/details/102347288

[remote rejected] HEAD -> refs/for/dev (no new changes)
这里有个方法解决,
http://blog.csdn.net/cuiaamay/article/details/51965325

更简单的方法:git commit --amend,然后什么也不做,直接保存退出就好,可以重新生成sha1,然后就可以push了。

gerrit merge后不能提交问题

需求:git 分支合并

问题:使用 git merge 在本地执行分支合并操作,然后想 push 到 gerrit 上评审入库,可是在提交时,提示:

! [remote rejected] HEAD -> refs/for/dev (no new changes)

分析:no new changes 的意思,是说,这个合并,是个线性的合并。而合并的那些历史的 commit 节点,在 gerrit 上都已经评审过了,都是已有的 change 单,所以 gerrit 认为没有新的提交,就不让你提交评审。

方法1: 在 git merge 的时候,加上 --no-ff 参数,是为了让它生成一个新的 commit,这样就可以提交了~(不过生成的 gerrit change 是看不到改动信息的)

方法2:不经过 gerrit,直接 push 入远程库。(不推荐)

报错commit is a merge but no -m option was given.

【git revert】报错commit is a merge but no -m option was given._allanGold的博客-CSDN博客

Git push remote rejected {change ### closed}

Git push remote rejected {change ### closed} ;https://www.cnblogs.com/zndxall/archive/2018/09/01/9571282.html

Git push remote rejected {change ### closed} - 加个小鸡腿 - 博客园

是因为和关掉的提交对应的Change_id一样导致的。

另一种可能是cherry-pick导致的:

之前提交的时候因为有merge,所以在gerrit服务器上审核的时候,我给abandoned了,因此从新处理提交的时候就出现了相同的tree, parent, author, committer以及log原文,这也就不难怪change-id也相同了。

添加一次可能导致Change-ID相同的情况,新的分支的提交是从另外的分支上cherry-pick过来的,所以当abandoned一次之后,再次cherry-pick时,Change-ID作为提交记录一并cherry-pick过来了,所以会重复。

简单的办法就是执行git commit --amend 删掉change_id就可以了,保存退出后会自动生成一个新的change_id,再次执行push就可以推到库了。

参考:

https://stackoverflow.com/questions/11972384/git-push-remote-rejected-change-closed

如果上面删除Change-Id的办法不可行,即git commit --amend 删除以后还是不行,我查资料看有些人说用git push -f   强推,我并不喜欢这种方式,不安全,真正我连尝试都没尝试就否定了他,然后我又想丢掉最后的提交记录重新提交可以不,执行git reset --soft HEAD~1 ,再git commit -m "commit again"写点信息,git push  还是报一样的错,

那怎么办呢?这里我建议采用生成补丁,打补丁的方式来重新提交,这是个安全可靠的方法,并且完全可行,可参考我的另一篇博客:

linux git patch 和patch以及git diff 命令

这里介绍下详细过程:

比如你执行了git  log -3 看到以下三个提交,最后的id3就是你提交不上的

commit id3

commit id2

commit id1

步骤:

(1)生成补丁:git format-patch -1 commit_id2  commit_id3    生成以后比如叫00001-commit-id1.patch  ,然后看看这个补丁的改动对应的是不是你的id3的修改

(2)移动补丁到工程外:mv 00001-commit-id1.patch   /root/    【目录随便选,但是要在工程目录外】

(3)确定无提交后版本硬回退,并pull最新代码,git reset --hard HEAD~3;   git pull

         注意,一定要确定没有要提交的代码了,因为--hard会把你的未提交的修改都丢掉。

(4)移动补丁回工程目录下:mv /root/00001-commit-id1.patch  ./

(5)检查补丁是否可用: git apply --stat 00001-commit-id1.patch

(6)打补丁:git am 00001-commit-id1.patch

(7)执行git log 看看是否打成功了,执行git show 看看修改对不对

(8)提交到gerrit:【比如要提交到develop分支】 git push origin HEAD:refs/for/develop

commit subject >65 characters; use shorter first paragraph

too many commit message lines longer than 70 characters

其实这些只是警告,错误应该是别的原因。如下:

[remote rejected] HEAD -> refs/for/UniStorOS-V100R001B62D001_RDMA_Adapt_000 (change http://10.165.104.246:8080/51192 closed)

Delta compression using up to 40 threads.
Compressing objects: 100% (170/170), done.
Writing objects: 100% (206/206), 32.95 KiB | 0 bytes/s, done.
Total 206 (delta 171), reused 38 (delta 36)
remote: Resolving deltas: 100% (171/171)
remote: Counting objects: 119939, done
remote: Processing changes: refs: 1, done
remote: (W) 79e4f24: commit subject >65 characters; use shorter first paragraph
remote: (W) 79e4f24: too many commit message lines longer than 70 characters; manually wrap lines
remote: (W) 092af96: commit subject >65 characters; use shorter first paragraph
remote: (W) 092af96: too many commit message lines longer than 70 characters; manually wrap lines
remote: (W) 07528af: commit subject >65 characters; use shorter first paragraph
remote: (W) 07528af: too many commit message lines longer than 70 characters; manually wrap lines
remote: (W) 5ddf297: commit subject >65 characters; use shorter first paragraph
remote: (W) d3a786b: commit subject >65 characters; use shorter first paragraph
remote: (W) d3a786b: too many commit message lines longer than 70 characters; manually wrap lines
remote: (W) 63f8537: commit subject >65 characters; use shorter first paragraph
remote: (W) 7688c12: commit subject >65 characters; use shorter first paragraph
remote: (W) 7688c12: too many commit message lines longer than 70 characters; manually wrap lines
To ssh://l24514@10.165.104.246:29418/ceph-L
 ! [remote rejected] HEAD -> refs/for/UniStorOS-V100R001B62D001_RDMA_Adapt_000 (change http://10.165.104.246:8080/51192 closed)
error: failed to push some refs to 'ssh://l24514@10.165.104.246:29418/ceph-L'
 

解决git cherry-pick 出现bad version 

git cherry-pick 出现bad version

在这里插入图片描述
git cherry-pick是本地特性,本地要有这个commit才可以被git cherry-pick。
所以先git pull 再进行pick就ok了,pick之后就可以接着解决冲突什么的了。

git delete remotes:远程引用不存在

git delete remotes:远程引用不存在

[root@localhost ofi]# git push origin --delete origin/fabric_lcx
error: unable to delete 'origin/fabric_lcx': remote ref does not exist
error: failed to push some refs to 'code.cestc.cn:storage/ceastor/depends/libfabric.git'

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值