git线上新建分支 线下拉取分支 回滚线上仓库版本

先去线上创建一个新的分支。克隆一个项目到指定分支,这个功能各个平台应该都是有的。
假设我这里新建的分支名称local

 本地新建一个和线上同样的分支名
 git branch local
 使用命令查看本地分支是否创建成功
 git branch (可以看到新建的分支名称 local)

本地切换分支 到 local

git checkout local

git pull提示以下信息

➜  kkbbi git:(local) git pull
From https://gitee.com/qs99527/kkbbi
 * [new branch]      local      -> origin/local
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> local

执行命名设置pull的分支即可

git branch --set-upstream-to=origin/local local

再次执行git pull命令

回滚线上版本

先执行git log

查看日志如下图所示

image.png

如果我想将线上local分支版本回退到 first commit 版本

git reset --hard 是本地代码回到某个版本不会影响到线上git仓库

这里应该使用 git reset --soft 将本地代码回滚到指定版本,后序版本信息将在暂存区显示。

先看看线上仓库的内容


image.png

可以明显看到有两个版本的信息。

现在执行命令git reset --soft 95c026b9339f1e7afa04a687f1dcd44b44259a0f

没有任何提示

执行 git log

image.png

只有一个版本信息了,现在git status 看看改动信息

image.png

可以看到代码都会在暂存区显示。现在可以执行git reset --hard将代码回退到指定信息
git reset --hard 95c026b9339f1e7afa04a687f1dcd44b44259a0f

image.png

代码回到这版本了。

然后将本地代码推送到线上仓库即可.

git push -f

最后仓库效果图


image.png

谢谢

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。