当前位置:   article > 正文

Git-Git常用命令、常见操作,创建镜像&切换新仓库、首次克隆、stash备份、查看及切换用户、修改默认分支、是否要保留本地修改等_merge made by the 'ort' strategy.

merge made by the 'ort' strategy.

Git在日常开发中经常使用,但有时候还是会忘记or遇到些奇奇怪怪的问题。以此记录,提醒自己~不定期更新~

1、新环境首次克隆

首次克隆仓库及其模块

git clone --recursive [仓库URL]
  • 1

仓库首次拉取模块

git submodule update --init --recursive
  • 1

更新子模块

git submodule update --recursive --remote
  • 1

2、是否要保留本地修改

保存修改

git stash #封存修改
git pull origin master
git stash pop #把修改还原
  • 1
  • 2
  • 3

放弃修改==回退

git reset --hard 
git pull origin master
  • 1
  • 2

3、提交代码

添加当前目录下的所有文件到暂存区

git add .
  • 1

提交暂存区到本地仓库中

git commit -m "本次提交代码概要简述"
  • 1

查看项目当前状态

git status
  • 1

将dev分支上的内容拉取到本地

git pull origin dev
  • 1

推送代码

git push
  • 1

4、stash备份

备份当前工作区内容,从最近的一次提交中读取相关内容,让工作区保证和上次提交的内容一致。同时,将当前工作区内容保存到Git栈中

git stash
  • 1

拉取服务器上当前分支代码

git pull
  • 1

从Git栈中读取最近一次保存的内容,恢复工作区相关内容。同时,用户可能进行多次stash操作,需要保证后stash的最先被取到,所以用栈(先进后出)来管理;pop取栈顶的内容并恢复

git stash pop
  • 1

显示Git栈内的所有备份,可以利用这个列表来决定从那个地方恢复。

git stash list
  • 1

清空Git栈

git stash clear
  • 1

5、查看及切换用户

查看用户名,github账户名

git config user.name
  • 1

查看邮箱

git config user.email
  • 1

切换用户

git config --global user.name “xxx”
  • 1

切换邮箱

git config --global user.email “xxx”
  • 1

6、创建镜像&切换新仓库

克隆为镜像

git clone --mirror [仓库URL]
  • 1

进入镜像文件夹

cd [repo folder]
  • 1

删除关联的origin的远程库

git remote rm origin
  • 1

创建新仓库后,更新为新远程仓库地址

git remote add origin [新的URL] 
  • 1

推送镜像

git push origin --all或git push origin --mirror
  • 1

推送tags

git push --tags
  • 1

确认gitlab上项目的分支及tags与原先一致
确保本地备份好了之后,可以清理下本地多余remote分支

git fetch -p
  • 1

7、修改默认分支

(1)在GitLab上新建项目后,进入项目,点击左侧Repository->Branches

可以看到里面只有一个受保护的默认分支main,此处无法删除。

然后新建分支master:点击右上角New branch,输入分支名字master,Create branch。

(2)再点击左侧Settings->Repository

点开Default branch,选择Default branch为master,Save Changes。

至此默认分支就是master了。

(3)此时还可以返回(1)的设置,将分支main删掉。

Ps.问题解决

Merge made by the ‘ort’ strategy.

查看commit记录, 找到远端本地冲突之前的commit
可以按“Q”退出git log状态

git log
  • 1

回退至某一版本,根据comminID决定。只回退了commit的信息

git reset --soft [commitID]
  • 1
git pull
  • 1

fatal: Cannot do soft reset with paths.

HEAD & index & working copy同时重置到你要reset到的那个commit上。执行了,你的本地修改可能就丢失了。

git reset --hard
  • 1

恢复git reset —hard的误操作

找到要退回的commitId

 git reflog
  • 1

然后再次执行

 git reset —hard commitId
  • 1

参考:
https://www.mimastech.com/2017/11/19/how-to-movemigrate-a-full-git-repository-from-github-to-gitlab-self-hosted-instance/
https://qa.1r1g.com/sf/ask/480571171/
https://blog.csdn.net/csdnlijingran/article/details/96425712

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/460688
推荐阅读
相关标签
  

闽ICP备14008679号