前言
记录一些工作中常见的git 使用问题。
文章目录
一、gitlab 代码分支 仓库迁移方法
- 先新建一个文件把老项目clone 下来。
git clone old_url.
cd XXX文件 - 切换到所要迁移的分支
git switch branchA
- (解除和原来的仓库关联)。
git remote rm origin branchA
- (和原来的仓库关联)。
git remote add origin branchB
- 推送到新分支
git push --set-upstream origin branchA
`
二、git 清空所有commit记录方法
# [git 清空所有commit记录方法]
说明:例如将代码提交到git仓库,将一些敏感信息提交,所以需要删除提交记录以彻底清除提交信息,以得到一个干净的仓库且代码不变
### 1.Checkout
> git checkout --orphan latest_branch
### 2\. Add all the files
> git add -A
### 3\. Commit the changes
> git commit -am "commit message"
### 4\. Delete the branch
> git branch -D master
### 5.Rename the current branch to master
> git branch -m master
### 6.Finally, force update your repository
> git push -f origin master
三、 git 强制回滚版本方法
强制回滚办法:
- 查看日志
git log
- 回退到指定版本
git reset --hard + 版本号
- 把当前分支强制提交到远程:
```git push -f origin branchB```
四、 本地仓库代码强制推送到远程分支 的方法
解决办法:
git push -f origin branchA(远程分支名)
本地分支强制推送到远程代码库
五、git本地仓库链接 github
git push -u origin master (远程分支名)
这一步是把本地仓库的内容推送到GitHub上 (把本地仓库分支master内容推送到元仓库去。)
总结
提示:这里对文章进行总结: