位置:首页 > 网络编程 > 资源/技巧
点击展开栏目简介

                                                    

Git:知识整理

分享到: 微信 新浪微博 更多

git文件夹是隐藏的项目,在“查看”中允许隐藏项目显示才可以看见。

设置全局的账号信息:

打开bash,进入到仓库目录(或者打开仓库目录文件夹,右键选择git Bash Here)。
    $ git config --global user.email "git账号邮箱"
    $ git config --global user.name "git账号名"

向空的仓库上传本地项目:

    进入项目目录,右键选择git bash here,打开bash窗口。    

    $ git remote add origin 这里替换成git上建立的空仓库路径;

    根据提示弹窗输入账号密码;

    等待上传完成;

下载文件pull:

    在本地项目文件夹下的bash命令窗口中执行git pull命令即可同步项目到本地

分支相关管理:

    在github上创建仓库:Create a new repository on the command line

    查看所有分支:git branch --all 

    在本地新建一个分支: git branch Branch1
    切换到你的新分支: git checkout Branch1
    将新分支发布在github上: git push origin Branch1
    在本地删除一个分支: git branch -d Branch1
    在github远程端删除一个分支: git push origin :Branch1   (分支名前的冒号代表删除)
    直接使用git pull和git push的设置
        git branch --set-upstream-to=origin/master master 
        git branch --set-upstream-to=origin/ThirdParty ThirdParty
        git config --global push.default matching
    更多相关知识:http://www.360doc.com/content/14/1029/10/13147830_420815353.shtml 

===========提交和获取==============

获取代码到本地
    首先要安装Git,然后使用命令把代码从Github上拷贝到本地:
        git clone https://github.com/<username>/<repository_name>

    如果是第一次使用,自己的repository还是空的,同样可以使用remote进行链接
        git remote add origin https://github.com/username/repository_name.git
提交更新到服务器

    本地新增一个test.html更新到服务器的完整过程为:

        git add test.html  #添加标记 (添加多个文件可以用git add *)
        git commit -m "代码提交信息" #备注信息

        git push origin master #把改动提交到服务器

        #流程结束

    删除一个文件并同步到服务器(直接在目录下把文件删掉是没有用的,必须用git rm删除文件)

        git rm test.html

        git commit -m "代码提交信息"
        git push origin master

从服务器获取更新

    git status 是一个很有用的命令,用来查看本地repository的状态,它会显示文件的新增/修改/删除的状态。

    如果服务端有更新,git status也会有相应的提示。

    如果服务端和本地文件都做了改动,使用git pull时就会提示冲突:

    这时候推荐手动检查一下文件的版本,到底需要哪个。有一个git mergetool可以帮助merge code。

    使用git checkout可以丢弃掉本地的改动,然后使用git pull去拿server上的最新更新。

        比如,我想丢弃一个文件的所有改动:git checkout routes.js
        然后再使用git pull,就可以拿到server上的版本的代码了。






上篇:搜狗浏览器使用自定义js脚本向网页注入js代码(可用于屏蔽广告等)

下篇:Phpstorm:解决phpstorm运行卡的问题

发表评论 ​共有​条评论
  • 匿名发表