Jianghc's Blog

Back

写在前面的#

之前在公司总结了一份github使用的新手入门手册,怎奈无法通过etrans带出(领导不让。。。。),只能重新总结,重新记录下遇到的相关问题。

相关trick#

Q1: 如何将github的公开项目fork为私有项目,原作者提交记录不丢失?#

首先在GitHub网页上新建一个私有repo(姑且叫它private-repo),然后依次执行以下命令就好了:

git clone --bare https://github.com/exampleuser/public-repo.git
cd public-repo.git
git push --mirror https://github.com/yourname/private-repo.git
cd ..
rm -rf public-repo.git
plaintext

这样,就可以像操作正常私有repo一样操作了,新的repo包含了原repo的所有信息,包括branch和tag等
当然也需要注意,我们是无法往原repo提交push requst的,因为没有public repo的权限
记录下我在执行中存在的问题:
https的方式始终连接不上, 会有对应的弹窗,而采用[email protected]:XXXXXX的链接则顺利push上去

Q2: git提交的代码如何回退到某个commit上#

准备工作:使用git log 命令查询所有的提交记录,找到对应的commit-id以及自己想要回退到的位置
回退到上一个版本

git reset --hard HEAD^
plaintext

回退到3次提交之前,以此类推提交到n次提交之前

git reset --hard HEAD~3
plaintext

回退/跳转到指定的commit位置上

git reset --hard commit-id
plaintext

最后一部,将本次代码强推上去

git push origin HEAD --force
plaintext

Q3: .gitignore上屏蔽了相关文件,但对应的github分支上依旧有未被屏蔽的文件或文件夹#

原因是因为在git忽略目录中,新建的文件在git中会有缓存,如果某些文件已经被纳入了版本管理中,就算是在.gitignore中已经声明了忽略路径也是不起作用的,因此我们需要先把本地缓存删除,然后再进行git的提交,这样就不会出现忽略的文件了。

解决方法: git清除本地缓存(改变成未track状态),然后再提交

$ git rm -r --cached .
$ git git add .
$ git commit -m 'update .gitignore'
$ git push -u origin master
plaintext

需要注意的事

  1. gitignore只能忽略那些原来没有被track的文件,如果某些文件已经被纳入了版本管理中,则修改.gitignore是无效的。
  2. 想要.gitignore起作用,必须要在这些文件不在暂存区中才可以,.gitignore文件只是忽略没有被staged(cached)文件
  3. 对于已经被staged文件,加入ignore文件时一定要先从staged移除,才可以忽略。

Q4: git在clone, push, pull代码中出现错误提示,无法直接下载#

报错1:gnutls_handshake() failed: The TLS connection was non-properly terminated. 原因:代理设置出现错误   解决方案: 重设代理(网上提供)

git config --global  --unset https.https://github.com.proxy
git config --global  --unset http.https://github.com.proxy
plaintext

若需使用代理,http协议和socket协议的配置分别如下,以8080端口为例:(未验证)

## http
git config --global http.https://github.com.proxy http://127.0.0.1:7890
git config --global https.https://github.com.proxy https://127.0.0.1:7890

## socket
git config --global http.proxy 'socks5://127.0.0.1:1080'
git config --global https.proxy 'socks5://127.0.0.1:1080'
plaintext

报错2:remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead 原因: git从2021年08月13日开始,对git操作进行身份验证时不在接受账户密码的形式,要求基于token的方式完成身份认证,需要在github上setting设置中完成令牌的设置,输入账户名以及对应的令牌密码,详细操作见: token生成

需要注意的事

  1. token的申请的明文秘钥显示只有一次,因此需要将其秘钥copy, 重新刷新网页则该token不存在
  2. 在进行代理初始化前,我通过ssh的方式依旧完成了代码的clone和push,例如[email protected]:TixiaoShan/LIO-SAM.git

未完待续,loading。。。。。

github使用的相关trick-----持续更新
https://525511.xyz/blog/github%E4%BD%BF%E7%94%A8%E7%9A%84%E7%9B%B8%E5%85%B3trick-%E6%8C%81%E7%BB%AD%E6%9B%B4%E6%96%B0
Author Haochen Jiang
Published at August 9, 2021
Comment seems to stuck. Try to refresh?✨