git常见问题解决方法

1. 将当前修改的文件提交到一个老的commit中了怎么解决?

#git reset --soft HEAD^     (重置到上一个commint)

#git reset HEAD reseted_file_name

#git commit --amend  (将当前commit提交)

#git commit -a (新建一个commit)

#git review


2. 

You are about to submit multiple commits. This is expected if you are

submitting a commit that is dependent on one or more in-review
commits. Otherwise you should consider squashing your changes into one
commit before submitting.


The outstanding commits are:


f8a639c (HEAD, Bug1415001) Fix live migration can not rollback resource correctly
7536bf3 Merge "Remove compability check for ratelimit_v3"


Do you really want to submit the above commits?

Type 'yes' to confirm, other to cancel: Aborting.

解决方法:

#git checkout master

#git pull origin master

#git checkout BRAND

#git rebase master

#git review


3.

remote: Resolving deltas: 100% (10/10)
remote: Processing changes: refs: 1, done    
remote: ERROR: missing Change-Id in commit message footer
remote: Suggestion for commit message:
remote: Fix live migration can not rollback resource correctly
remote: 
remote: When some exception occur in funciton _live_migration,
remote: the _rollback_live_migration() will be called, and the variable
remote: "migrate_date" must be imported, which as the specific params,
remote: otherwise the instance path will be not deleted and causes next
remote: live-migration to fail.
remote: 
remote: Closes-Bug: #1415001
remote: 
remote: Change-Id: Icd34ce4f1b509dd6d228ea2f620d34ac5e529951
remote: 
remote: Hint: To automatically insert Change-Id, install the hook:
remote:   gitdir=$(git rev-parse --git-dir); scp -p -P 29418 Zhengguang@review.openstack.org:hooks/commit-msg ${gitdir}/hooks/
remote: 
remote: 
To ssh://Zhengguang@review.openstack.org:29418/openstack/nova.git
 ! [remote rejected] HEAD -> refs/publish/master/Bug1415001 (missing Change-Id in commit message footer)
error: failed to push some refs to 'ssh://Zhengguang@review.openstack.org:29418/openstack/nova.git'

解决方法:

#gitdir=$(git rev-parse --git-dir); scp -p -P 29418 Zhengguang@review.openstack.org:hooks/commit-msg ${gitdir}/hooks/

#git review


4. git连接拒绝

ssh -T git@github.com


[root@control-compute00 nova]# ssh-add
Could not open a connection to your authentication agent.
[root@control-compute00 nova]# ssh-agent bash
[root@control-compute00 nova]# ssh-add -l
The agent has no identities.
[root@control-compute00 nova]#  ssh-add ~/.ssh/id_rsa
Identity added: /root/.ssh/id_rsa (/root/.ssh/id_rsa)

5. 

在使用Git的过程中,有时可能会有一些误操作

比如:执行checkout -f 或 reset -hard 或 branch -d删除一个分支

结果造成本地(远程)的分支或某些commit丢失

可以通过reflog来进行恢复,前提是丢失的分支或commit信息没有被git gc清除

一般情况下,gc对那些无用的object会保留很长时间后才清除的

reflog是git提供的一个内部工具,用于记录对git仓库进行的各种操作

可以使用git reflog show或git log -g命令来看到所有的操作日志

恢复的过程很简单:

1. 通过git log -g命令来找到我们需要恢复的信息对应的commit_id,可以通过提交的时间和日期来辨别

2. 通过git branch recover_branch commit_id 来建立一个新的分支

这样,我们就把丢失的东西给恢复到了recover_branch分支上了



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值