Commands
# linux输入ssh-keygen 得到公钥,找到路径将.pub内容复制到gitlab里面就可以了
# step 1 pull仓库文件夹
mkdir gitlab_project
cd gitlab_project
git clone https:*.git
cd detection_ncnn
# step 2 将需要上传的文件移动到拉取的文件夹内
cp ../../det_ncnn_mips/* . -r
git switch -c main
git add . # 所有或者特定文件
git commit -m "initial commit"
# step 3 push上传 注意是main 不是master
git push -u origin main # git push
# 版本切换
git checkout VERSION_NUM
删除远程分支提交历史
命令整理
git remote prune origin 删除本地有但在远程库已经不存在的分支 <br>
git clone -b 分支名 地址 <br>
git remote add origin git@github.com:XXXXX/demo.git 新增远程仓库<br>
git remote set-url origin git@github.com:XXXXX/demo.git 修改远程仓库<br>
git remote set-url --add origin git@github.com:XXXXX/demo.git 添加多个远程仓库<br>
git stash 不提交工作区内容 <br>
git stash pop 恢复工作区<br>
git fetch 拉取远程分支<br>
git reset --hard <commit ID号> 回滚<br>
git push -f origin master 推送到远程分支 <br>
git diff 查看工作区和暂存区的区别 <br>
查看暂存区和版本库之间的区别 <br>
git diff HEAD 查看工作区和版本库之间的区别 <br>
git status 查看当前的工作状态<br>
git push --set-upstream origin online_help_20191024 推远程分支<br>
git push origin --delete dev20181018 删除远程分支<br>
git branch -d dev20181018 删除本地分支<br>
git cherry-pick 285c9477a759abdee94099e25e75e39e8c77d46b 合并指定版本
版本切换
# 版本切换,但HEAD->main不变
git checkout <commit_hash_id>
# 版本还原最新main
git checkout main
合并冲突
储藏 stash
Github免密登陆
- 用户密码需要创建token,输入的密码是token
- 不想每次输入密码
git config --global credential.helper store
记录下次输入信息,以后就不用了。(如果输入错误,请重置)
git config --system --unset credential.helper)
- 如果clone不了,可能是代理问题,配置代理
git config --global http.proxy 127.0.0.1:7890
git config --global --unset http.proxy 重置
# 查看配置
git config --global --list
# 配置用户名和邮箱
git config --global user.name "用户名"
git config --global user.email "邮箱"
# 生成公钥
ssh-keygen -t rsa -C "邮箱"
cat ~/.ssh/id_rsa.pub
# 保存密码免密登陆
git config --global credential.helper store
# 配置代理
git config --global http.proxy 127.0.0.1:7890
# 校验连接
ssh -T git@github.com
修改commit信息
https://blog.csdn.net/weixin_43314519/article/details/123317135
修改上次提交的commit信息
https://juejin.cn/post/7036174938306248717
git commit --amend --author="果冻<liguodongiot@163.com>" --no-edit
git push --force
修改历史commit
1 找到历史commid id
git log
2 rebase id
git rebase -i $commid_id
3 编辑第一行的pick为edit,保存
4 git commit --amend --author="mingjie " --no-edit
5 如果有冲突就修改,然后git add $conflict_files
6 git rebase --continue
7 git push --force # 推送到remote
修改历史提交者的邮箱
#!/bin/sh
# 修改历史提交者的邮箱
git filter-branch -f --env-filter '
old_email="old@email.com"
new_email="new@email.com"
if [ "$GIT_COMMITTER_EMAIL" = "$old_email" ]
then
export GIT_COMMITTER_EMAIL="$new_email"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$old_email" ]
then
export GIT_AUTHOR_EMAIL="$new_email"
fi
' HEAD
Blog
白色箭头文件夹
- 当git上传含有.git子文件夹时,子文件夹会出现白色箭头,并且不会被上传。
- 解决:需要删除.git重新上传, (git rm –cached $dir_name)
git rm --cached themes/matery/
git add themes/matery
git commit -m "add theme"
git push