git提交本地代码到新的分支

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/quanqxj/article/details/82743983

问题场景:

在feature/redis分支做了一些修改,但是不想提交到远程的feature/redis分支,想新建一个分支feature/login保存代码。

操作方法:

  1. 添加本地需要提交代码
    git add .

  2. 提交本地代码
    git commit -m “添加spring security安全登录验证”

  3. push 到git仓库
    git push origin feature/redis:feature/login

仓库中原本没有feature/login,提交后会生成新分支feature/login,并将本地基于feature/redis修改的代码提交到feature/login中

  1. 切换新分支
    git checkout -b feature/login origin/feature/login

当你切回到原来的分支时,你会发现,有如下提示:
localhost:springcloud quanxj$ git checkout feature/redis
Switched to branch ‘feature/redis’
Your branch is ahead of ‘origin/feature/redis’ by 1 commit.
(use “git push” to publish your local commits)

  1. 回滚代码

    在此利用git 回滚,回到上一次的提交状态:

  • 查看目前所有提交:
    git log

  • 回滚到commit-id,将commit-id之后提交的commit都去除
    git reset --hard commit-id

猜你喜欢

转载自blog.csdn.net/quanqxj/article/details/82743983