美文网首页
git 使用手册

git 使用手册

作者: 大继 | 来源:发表于2020-04-09 19:38 被阅读0次

    删除分支

    $ git branch -d branchName

    创建分支

    $ git branch branchName

    切换分支

    $ git checkout branchName

    创建并切换到分支上

    $ git checkout -b branchName

    合并分支

    $ git merge branchName

    抓取分支-- 抓取远程分支信息到本地

    git fetch -a

    多人协作时,大家都会往master和dev分支上推送各自的修改。

    现在,模拟一个你的小伙伴,可以在另一台电脑(注意要把SSH Key添加到GitHub)或者同一台电脑的另一个目录下克隆:

    $ git clone git@github.com:michaelliao/learngit.git
    Cloning into 'learngit'...
    remote: Counting objects: 46, done.
    remote: Compressing objects: 100% (26/26), done.
    remote: Total 46 (delta 16), reused 45 (delta 15)
    Receiving objects: 100% (46/46), 15.69 KiB | 6 KiB/s, done.
    Resolving deltas: 100% (16/16), done.

    当你的小伙伴从远程库clone时,默认情况下,你的小伙伴只能看到本地的master分支。不信可以用git branch命令看看:

    $ git branch

    • master

    现在,你的小伙伴要在dev分支上开发,就必须创建远程origin的dev分支到本地,于是他用这个命令创建本地dev分支:

    $ git checkout -b dev origin/dev

    git pull也失败了,原因是没有指定本地dev分支与远程origin/dev分支的链接,根据提示,设置dev和origin/dev的链接

    $ git branch --set-upstream dev origin/dev
    Branch dev set up to track remote branch dev from origin.

    再pull:

    $ git pull
    Auto-merging hello.py
    CONFLICT (content): Merge conflict in hello.py
    Automatic merge failed; fix conflicts and then commit the result.

    本地新建分支,提交到远程 或 删除远程分支

    git push origin local_branch:remote_branch

    • 这个操作,local_branch必须为你本地存在的分支,remote_branch为远程分支,如果remote_branch不存在则会自动创建分支。
    • 类似,git push origin :remote_branch, [local_branch留空的话则是删除远程remote_branch分支]

    将本地仓库和远程仓库关联

    git remote add origin git@github.com:YotrolZ/helloTest.git

    git ignore 文件不生效解决

     把某些目录或文件加入忽略规则,按照上述方法定义后发现并未生效,
     原因是.gitignore只能忽略那些原来没有被追踪的文件,
     如果某些文件已经被纳入了版本管理中,则修改.gitignore是无效的。
     那么解决方法就是先把本地缓存删除(改变成未被追踪状态),然后再提交:
    
    git rm -r --cached .
    git add .
    git commit -m 'update .gitignore'

    相关文章

      网友评论

          本文标题:git 使用手册

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