Git自学|在实践中学习

小结

GitHub开源项目搜索

  1. 搜索名字 in:name xxx
  2. 搜索描述 in:description xxx
  3. 搜索readme in:readme xxx
  4. 按stars stars:>2000
  5. 按fork fork:>3000
  6. 仓库大小搜索 size:>=5000 [说明5000大小是5000k]
  7. 按更新时间 pushed:>2020-01-01
  8. 按语言 language:xxx
  9. 按作者名 user:xxx [注意:后面不要有空格]
  10. 搜索的方式可以组合
  11. 更多高级搜索 https://github.com.search/advanced
// 找一个基于springboot的开源项目
in:name: springboot stars:>4000 pushed:>2020-01-01 language:java forks:>10000 // name中有关键字springboot
// 找一个基于python的开源项目
in:readme: spider 淘宝 STARS:>1000 language:python pushed:>2020-09-01 // readme中有关键字spider和淘宝

创建新的协同项目

1 github创建一个新的项目project,复制url
2 目录filename下打开terminal

git clone URL

3 目录下复制了该项目,filename/project
4 进入project,进行add\commit\push

合并远程更新和本地更新

# 若远程有更新,须pull至本地
git stash # 将本地加入缓存/新分支
git pull
git stash Pop # 将缓存拉出,与stash是一对出现
# 根据冲突提示fix conflict and merge;打开源文件,删除冲突内容和提示内容,此时文件名仍报红,代表待提交
git status # 查看本地哪些文件做了变动
# 若本地有更新,须push至远程
git add <file/folder> # iDea可设置提添加文件时自动add
git commit -m "xxx"
git push
# 其他
git branch // 查看分支(github中main下拉框查看branch)
git branch -a // 查看完整分支

使用中的问题

问题1: 网络问题

fatal: unable to access 'https://github.com/xxx/': Failed to connect to github.com port 443 after 21103 ms: Couldn't connect to server

fatal: unable to access 'https://github.com/xxx/': Empty reply from server

fatal: unable to access 'https://github.com/xxx/': Recv failure: Connection was reset

解决:多次尝试or代理

问题2: Everything up-to-date

第一次 git push 返回“提交区所有内容都是最新的”

~ git push
Everything up-to-date

解决:push前必须add file & commit,添加对应文件,并编辑提交信息

~ git add <file>
~ git commit -m "..."
~ git push
Everything up-to-date

问题3:failed to push

在另一台终端上使用git

~ git commit -a
~ git push
! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'https://github.com/xxx'

hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., ‘git pull …’) before pushing again.
hint: See the ‘Note about fast-forwards’ in ‘git push --help’ for details.
解决:push前需要pull

~ git pull
~ git push
 ! [rejected]        main -> main (non-fast-forward)
error: failed to push some refs to 'https://github.com/xxx'

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.

~ git pull skeleton main
error: Pulling is not possible because you have unmerged files.

hint: Fix them up in the work tree, and then use ‘git add/rm ’
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.
问题:存在冲突未处理,不能上传

问题4:nothing to commit, working tree clean

git stash
git add <file>
git commit -m 'xxx' // 或这时 git status 也会报如下错

On branch main
Your branch is up to date with ‘origin/main’
nothing to commit, working tree clean

解决:stash缓存后,须stash pop缓存出,才能commit

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值