git使用中遇到的问题(个人笔记)

【版权申明】转载请附上出处链接

git使用中遇到的问题(个人笔记)

关于git 1.x中的match与git 2.x中的simple

$git push 
warning: push.default is unset; its implicit value has changed in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the traditional behavior, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.

Since Git 2.0, Git defaults to the more conservative 'simple'
behavior, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch.

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

‘matching’ 参数是 Git 1.x 的默认行为,其意是如果你执行 git push 但没有指定分支,它将 push 所有你本地的分支到远程仓库中对应匹配的分支。

而 Git 2.x 默认的是 simple,意味着执行 git push 没有指定分支时,只有当前分支会被 push 到你使用 git pull 获取的代码。

建议使用git 2.x中的行为:

git config --global push.default simple

fatal: The remote end hung up unexpectedly

$git push
Counting objects: 834, done.
Compressing objects: 100% (788/788), done.
packet_write_wait: Connection to xxx.xxx.xxx.xxx port yyy: Broken pipe
error: pack-objects died of signal 13
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'ssh://xxxxxxxxxxxxxxxx.git'

导致上面的现象可能存在几种原因,看情况选择处理的办法:

  1. 你的仓库是空的,刚建立的仓库。你没办法直接把现有的项目代码直接丢进去,需要先创建一个readme文件并上传;
  2. 网络不太好,中途断了,多试几次;
  3. [参考自网上]用 ssh 命令连接服务器之后,如果一段时间不操作,再次进入 Terminal 时会有一段时间没有响应,然后就出现错误提示(Write failed: Broken pipe),只能重新用 ssh 命令进行连接。解决办法如下:
# 修改个人的ssh配置,如果该文件不存在那么久创建它。
# 如果你想修改所有人的,在/etc/ssh/ssh_config文件中配置;
$vi ~/.ssh/config

# 填入以下内容:
Host *
  ServerAliveInterval 300    
  ServerAliveCountMax 2

git - 提交空目录

不知道是git的创始人不喜欢空文件夹还是怎么回事,反正空文件夹是没有办法上传到git上的。(这让我上传文件系统的时候就很尴尬,像什么/dev等目录就没有上传到)

解决办法:
  在目录下创建 .gitkeep 文件,然后在项目的 .gitignore 中设置不忽略 .gitkeep。
  .gitkeep 是一个约定俗成的文件名并不会带有特殊规则。

git commit之后,想撤销commit

# 注意,这仅仅是撤回commit操作,你写的代码仍然保留。
$git reset --soft HEAD^

HEAD^的意思是上一个版本,也可以写成HEAD~1
如果你进行了2次commit,想都撤回,可以使用HEAD~2

–mixed
不删除工作空间改动代码,撤销commit,并且撤销git add操作
这个为默认参数,git reset --mixed HEAD^ 和 git reset HEAD^ 效果是一样的。

–soft
不删除工作空间改动代码,撤销commit,不撤销git add

–hard
删除工作空间改动代码,撤销commit,撤销git add
注意完成这个操作后,就恢复到了上一次的commit状态。

git commit之后,想修改commit的注释

# 此时会进入默认vim编辑器,修改注释完毕后保存就好了。
$git commit --amend
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

安河桥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值