美文网首页
Git合并commits为一条记录提交到master分支(用于发

Git合并commits为一条记录提交到master分支(用于发

作者: 小石头糖糖 | 来源:发表于2020-05-27 13:46 被阅读0次

    一、不小心把所有记录推送到远程master分支, 撤回步骤如下

    (若尚未提交, 不必执行此区域命令, 可直接参考二)

    S1: 查看分支
    git branch
    S2: 切换到master分支
    git checkout master
    S3: 查看提交记录
    git log
    S4: 撤销commit, 回滚到xxx记录
    git reset --hard xxx
    S5: 撤销后强制推送到远程上
    git push --force || (git push -f origin master)

    如果master分支被保护出现[remote rejected], 先解保才能推送成功:
    在git上项目的settings>repo>Protected Branches中设置unprotect.

    二、在dev分支开发完成后, 合并到master上的步骤如下

    S1: 切换到master分支上
    git checkout master
    S2: 拉取mater上远程代码
    git pull
    S3: 合并dev上代码到master上
    git merge --squash dev
    ( --squash 将所有提交合并为一条记录 )
    S4: 查看状态
    git status

    如果遇到多个文件多处冲突问题
    git checkout --ours ./components
    ( --ours批量处理 components下采用远程原有代码)
    git checkout --theirs ./components
    ( --theirs批量处理 components下采用本地新写代码)

    S5: 最后提交代码并推送
    git add .
    git commit -m "xxx"
    git push

    Ps: 解决报错 >>

    error: The following untracked working tree files would be overwritten by merge:
        platform_ios/Rea/Feature-iOS.xls
        platform_ios/Rea/注意事项.txt
    Please move or remove them before you merge.
    

    s1: 找到platform_ios/Rea目录下 Feature-iOS.xsl、注意事项.txt两个文件将其删除;
    s2: 重新拉取远程代码到本地: git pull origin master;
    s3: 执行git clean -d -fx删除没有git add的文件;
    s4: 将正常的代码进行提交:
    git add .
    git commit -m "***"
    git push

    Add: git仓库地址变更 >>

    git remote  //查看远程库的信息;
    git remote -v //查看远程库详细信息;
    git remote rm origin //删除旧地址;
    git remote add origin [url] //添加新地址;
    

    相关文章

      网友评论

          本文标题:Git合并commits为一条记录提交到master分支(用于发

          本文链接:https://www.haomeiwen.com/subject/dpqwahtx.html