Git

353 字
2 分钟
Git

LFS安装#

https://github.com/git-lfs/git-lfs/blob/main/INSTALLING.md

Terminal window
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
apt-get install git-lfs

初始化#

设置用户名和密码

Terminal window
git config --global user.name "xwysyy"
git config --global user.email ""

注意,可能存在推送或者拉取失败的情况,需要设置端口代理,这里用的是v2rayN,转发端口为1080

Terminal window
# 配置代理
git config --global http.proxy 127.0.0.1:10808
git config --global https.proxy 127.0.0.1:10808
# 查看代理
git config --global --get http.proxy
git config --global --get https.proxy
# 取消代理
git config --global --unset http.proxy
git config --global --unset https.proxy

连接远程仓库#

Terminal window
git remote add origin <....git>

查看是否连接

Terminal window
git remote -v

git pull#

Terminal window
# 拉取默认分支
git pull
# 或使用带参数 pull, 拉取指定分支
git pull origin master

git add#

将文件添加到暂存区

Terminal window
git add <file_name>

将所有修改过的文件添加到暂存区

Terminal window
git add .

git commit#

提交暂存区的文件到本地仓库

Terminal window
git commit -m commit_message

git push#

Terminal window
git push
# git push origin master

清除cache#

Terminal window
git rm -r --cached .

清除git仓库的所有提交记录#

  • 创建新分支
Terminal window
git checkout --orphan newBranch
  • 添加所有文件(除了.gitignore中声明排除的)
Terminal window
git add -A
  • 提交跟踪过的文件(Commit the changes)
Terminal window
git commit -am init
  • 删除master分支
Terminal window
git branch -D master
  • 重命名当前分支为master
Terminal window
git branch -m master
  • 重新指定远端
Terminal window
git remote add origin "xxx.git"
  • 已经有了就是git remote set-url origin ..

  • 强制提交到远程master分支

Terminal window
git push -f origin master

git回退到某个版本#

Terminal window
git reset --hard <commit>
git push -f -u origin master
Git
https://www.xwysyy.cn/posts/git/
作者
xwysyy
发布于
2023-12-08
许可协议
CC BY-NC-SA 4.0

文章目录