0%

Git相关的笔记

Git撤销

commit后撤销

场景: 本地Repo不小心新增加大文件,不想上传到远端

git log 找到要恢复到的commit_id
git reset --hard commit_id

add后撤销

git reset HEAD

Git Push过程中遇到的问题现象以及其解决

背景

收到一个代码的压缩包,解压发现里面有 .git 目录,TortoiseGit右键可以看到提交历史等; 故想将其导入本地GitLab中以保留提交记录;

遇到的问题现象

按一般的方式 git remote remove/ git remote add 修改仓库的地址后,git push报错:

git branch 返回

解决办法

git checkout mastergit checkout -f master
git push

Git中如何上传大文件

  1. Git LFS的官网 下载Git LFS后安装(或在ubuntu中直接使用apt install git-lfs安装)
  2. 在git项目目录中执行 git lfs install
  3. git lfs track "*.h5" (这里大文件以 h5结尾)
  4. git add .gitattributes
  5. git commit
  6. git push
  7. 之后就可以类似与普通文件那样添加、提交大文件了:
  8. git add nsfw.299x299.h5
  9. git commit
  10. git push

克隆包含 Git LFS 文件的远程仓库

git lfs clone

如果不安装git-lfs

git lfs uninstall后,大文件将形如

version https://git-lfs.github.com/spec/v1
oid sha256:751baea102ae63f0990607883ff819cfe18276d5116605673c5ff7e42e34e945
size 94653016

Git中使用https的库,如何不用每次都输入密码

vim ~/.git-credentials
内容:

https://{username}:{password}@gitee.com

在库中执行
git config --global credential.helper store

CentOS 7 安装Gitlib

环境

  • CentOS 7 64bit

步骤

  1. 参考官网的步骤
  2. 修改vim /etc/yum.repos.d/gitlab_gitlab-ce.repo
    [gitlab-ce]
    name=gitlab-ce
    baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7
    repo_gpgcheck=0
    gpgcheck=0
    enabled=1
    gpgkey=https://packages.gitlab.com/gpg.key
  3. 更新yum缓存 yum makecache
  4. EXTERNAL_URL=”http://<gitlab.example.com>” yum install -y gitlab-ce
  5. 上述URL在 /etc/gitlab/gitlab.rb 中配置; 如需修改, 修改后需要 gitlab-ctl reconfigure

TroubleShooting

报错/opt/gitlab/embedded/bin/psql: undefined symbol: PQsetErrorContextVisibility

因系统中已经安装了 postgresql; 解决方案是export LD_LIBRARY_PATH=/opt/gitlab/embedded/postgresql/9.6.8/lib/:$LD_LIBRARY_PATH
重新运行 gitlab-ctl reconfigure

参考资料

  1. 安装gitlab
  2. gitlab汉化

Gitlab密码重置

场景: 忘记root密码,邮箱没有配置
gitlab-rails console production

user = User.where(id:1).first
user.password='密码'
user.password_confirmation='密码'
user.save!

Gitlab安装需要较多的资源,要轻量级的参考 通过HTTP访问Git服务器