• Git常用


    Git

    第一次使用
    从origin上clone代码
    Eg:
    cd myGitProj
    git clone o2o-business-admin
    本地会自动生成和origin/master相同的master

    git pull origin dev_dosh:dosth
    //git pull <远程库名> <远程分支名>:<本地分支名>
    //从远程dev_dosh分支拉代码到本地dosth分支并merge,省略冒号及后面的,默认与当前分支merge
    //等价于 git fetch origin dev_dosh:dosth && git merge dosth

    git checkout origin/remoteName -b localName
    获取远程分支remoteName 到本地新分支localName,并跳到localName分支

    git branch
    //可查看当前分支处于master


    git checkout -b dev_dosth
    //创建并切换到dev_dosh分支,该分支与当前分支(master)相同

    ...modify somefiles...

    git add.
    git commit -m "what I did"

    git push origin dev_dosth:dosth
    //git push <远程主机名> <本地分支名>:<远程分支名>
    //在远程创建dosth分支并将本地dev_dosth分支内容merge上去

    test my modifition

    gitlab上提交merge request

    上线后可删除分支


    第二次用
    git checkout master
    git pull

    //git "undo" cmd

    add前撤销所有改动
    git checkout .

    撤销sfile.txt的改动
    git checkout -- sfile.txt

    撤销add
    git reset filename

    撤销commit
    git reset oldCommitId

    抛弃当前合并冲突的处理过程并尝试重建合并前的状态
    git merge --abort

    git 合并多个commit
    git rebase -i commitId
    fixup/squash/pick/……
    https://www.jianshu.com/p/964de879904a


    commit后、merge到master前撤销对file的改动,使其恢复到与master相同
    git rm --cached file

    ############################

    git merge和rebase的选择

    总结:

    以dev merge到master为例,即:

    git checkout dev

    git merge/rebase master

    merge:

    多个分支的时间线将严格按照统一时间线进行合并,即dev和master的时间线上会有交叉

    rebase:

    会把整个dev分支移到master分支后面,master上如果有新的提交(时间上后于本dev),时间线上也会先于dev的commit【rebase代替合并

    也就是说,rebase会改写历史纪录-----黄金法则

    可考虑 git rebase -i master

    ###########################

    What is the difference between 'origin' and 'remote' in git commands?

    No, they don't mean the same thing.

    remote, in git-speak, refers to any remote repository, such as your GitHub or another git server.

    origin is the, by convention, default remote name in git. When you do a git clone <url><url> is automatically added to your local repo under the name origin. You can, of course, add other remotes under different names using git remote add.

    When you do git push -u origin master, what it means is "push everything from my local master to the remote named origin". The structure of this command is, of course, more general - the more general form is git push -u <remote> <branch>, which will push the branch named branch to the designated remote, creating it at the far end if the remote doesn't already have it (that's what the -u flag does).

    As a further addendum, git push, by default, will push the current branch to origin, corresponding to git push origin <current-branch>.

    ###########################

    大部分情况下,不知道怎么办

    git status 会告诉你

    https://www.jianshu.com/p/67f20d19605a


    将本地项目push到github参考:

    Git的使用--如何将本地项目上传到Github

  • 相关阅读:
    linux删除大小为0,linux下批量删除空文件(大小等于0的文件) 和 乱码文件
    在 VMware 上启用 SCSI_ID
    vmware中的RHEL scsi_id不显示虚拟磁盘的wwid的问题
    spring cloud 集成和使用
    spring cloud alibaba 常见用法
    rabbitmq 和 erlang window 安装
    系统架构 垂直拓展 水平拓展的区别
    SPI 服务提供者接口
    摩斯密码
    vue3 pinia 和 vuex的对比
  • 原文地址:https://www.cnblogs.com/peanutk/p/8494441.html
Copyright © 2020-2023  润新知