zoukankan      html  css  js  c++  java
  • Git&GitHub学习和运用(3.GitHub实战运用)

     配置全局忽略文件.gitignore

      例举dotNet开发的一个场景来说明“忽略文件”的作用,在开发过程中往往在编辑代码后,VS在每次编译后会生成一些项目构建文件例如bin目录、obj目录等。然而这些文件并不需要进行版本控制,因为每个人每次编译后都会自动生成,如果频繁上传至Git那么会造成空间的占用,其他人检出文件时增加下载的时间。所以在第一次将项目使用Git版本控制时,就需要创建该文件,来避免类似的问题。

      基于以上的场景,说到底就是我们不希望项目中的文件进行版本控制(忽略掉),那么此时就可以配置一个全局的忽略文件.gitignore。

      创建全局的忽略文件.gitignore步骤如下:

       1.选择一个目录(推荐Git安装目录),在该目录打开Git命令行工具,输入命令(创建忽略文件):

    touch .gitignore_global

       2. 将该文件配置为全局的忽略文件,输入命令:

    git config --global core.excludesfile ~/.gitignore_global

      

      3.打开.gitignore_global文件添加忽略规则,在这里不详细介绍规则的编写,因为这些东西往往都是通用化的都用现有的模板拿来用,如果不是专门的版本控制系统管理员,那就不必浪费时间研究。如下附上一个模板,可以根据模板内容自行扩展:

    ## Ignore Visual Studio temporary files, build results, and
    ## files generated by popular Visual Studio add-ons.
    
    # User-specific files
    *.suo
    *.user
    *.userosscache
    *.sln.docstates
    
    # User-specific files (MonoDevelop/Xamarin Studio)
    *.userprefs
    
    # Build results
    [Dd]ebug/
    [Dd]ebugPublic/
    [Rr]elease/
    [Rr]eleases/
    x64/
    x86/
    bld/
    [Bb]in/
    [Oo]bj/
    [Ll]og/
    
    # Visual Studio 2015 cache/options directory
    .vs/
    # Uncomment if you have tasks that create the project's static files in wwwroot
    #wwwroot/
    
    # MSTest test Results
    [Tt]est[Rr]esult*/
    [Bb]uild[Ll]og.*
    
    # NUNIT
    *.VisualState.xml
    TestResult.xml
    
    # Build Results of an ATL Project
    [Dd]ebugPS/
    [Rr]eleasePS/
    dlldata.c
    
    # DNX
    project.lock.json
    project.fragment.lock.json
    artifacts/
    
    *_i.c
    *_p.c
    *_i.h
    *.ilk
    *.meta
    *.obj
    *.pch
    *.pdb
    *.pgc
    *.pgd
    *.rsp
    *.sbr
    *.tlb
    *.tli
    *.tlh
    *.tmp
    *.tmp_proj
    *.log
    *.vspscc
    *.vssscc
    .builds
    *.pidb
    *.svclog
    *.scc
    
    # Chutzpah Test files
    _Chutzpah*
    
    # Visual C++ cache files
    ipch/
    *.aps
    *.ncb
    *.opendb
    *.opensdf
    *.sdf
    *.cachefile
    *.VC.db
    *.VC.VC.opendb
    
    # Visual Studio profiler
    *.psess
    *.vsp
    *.vspx
    *.sap
    
    # TFS 2012 Local Workspace
    $tf/
    
    # Guidance Automation Toolkit
    *.gpState
    
    # ReSharper is a .NET coding add-in
    _ReSharper*/
    *.[Rr]e[Ss]harper
    *.DotSettings.user
    
    # JustCode is a .NET coding add-in
    .JustCode
    
    # TeamCity is a build add-in
    _TeamCity*
    
    # DotCover is a Code Coverage Tool
    *.dotCover
    
    # NCrunch
    _NCrunch_*
    .*crunch*.local.xml
    nCrunchTemp_*
    
    # MightyMoose
    *.mm.*
    AutoTest.Net/
    
    # Web workbench (sass)
    .sass-cache/
    
    # Installshield output folder
    [Ee]xpress/
    
    # DocProject is a documentation generator add-in
    DocProject/buildhelp/
    DocProject/Help/*.HxT
    DocProject/Help/*.HxC
    DocProject/Help/*.hhc
    DocProject/Help/*.hhk
    DocProject/Help/*.hhp
    DocProject/Help/Html2
    DocProject/Help/html
    
    # Click-Once directory
    publish/
    
    # Publish Web Output
    *.[Pp]ublish.xml
    *.azurePubxml
    # TODO: Comment the next line if you want to checkin your web deploy settings
    # but database connection strings (with potential passwords) will be unencrypted
    #*.pubxml
    *.publishproj
    
    # Microsoft Azure Web App publish settings. Comment the next line if you want to
    # checkin your Azure Web App publish settings, but sensitive information contained
    # in these scripts will be unencrypted
    PublishScripts/
    
    # NuGet Packages
    *.nupkg
    # The packages folder can be ignored because of Package Restore
    **/packages/*
    # except build/, which is used as an MSBuild target.
    !**/packages/build/
    # Uncomment if necessary however generally it will be regenerated when needed
    #!**/packages/repositories.config
    # NuGet v3's project.json files produces more ignoreable files
    *.nuget.props
    *.nuget.targets
    
    # Microsoft Azure Build Output
    csx/
    *.build.csdef
    
    # Microsoft Azure Emulator
    ecf/
    rcf/
    
    # Windows Store app package directories and files
    AppPackages/
    BundleArtifacts/
    Package.StoreAssociation.xml
    _pkginfo.txt
    
    # Visual Studio cache files
    # files ending in .cache can be ignored
    *.[Cc]ache
    # but keep track of directories ending in .cache
    !*.[Cc]ache/
    
    # Others
    ClientBin/
    ~$*
    *~
    *.dbmdl
    *.dbproj.schemaview
    *.jfm
    *.pfx
    *.publishsettings
    node_modules/
    orleans.codegen.cs
    
    # Since there are multiple workflows, uncomment next line to ignore bower_components
    # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
    #bower_components/
    
    # RIA/Silverlight projects
    Generated_Code/
    
    # Backup & report files from converting an old project file
    # to a newer Visual Studio version. Backup files are not needed,
    # because we have git ;-)
    _UpgradeReport_Files/
    Backup*/
    UpgradeLog*.XML
    UpgradeLog*.htm
    
    # SQL Server files
    *.mdf
    *.ldf
    
    # Business Intelligence projects
    *.rdl.data
    *.bim.layout
    *.bim_*.settings
    
    # Microsoft Fakes
    FakesAssemblies/
    
    # GhostDoc plugin setting file
    *.GhostDoc.xml
    
    # Node.js Tools for Visual Studio
    .ntvs_analysis.dat
    
    # Visual Studio 6 build log
    *.plg
    
    # Visual Studio 6 workspace options file
    *.opt
    
    # Visual Studio LightSwitch build output
    **/*.HTMLClient/GeneratedArtifacts
    **/*.DesktopClient/GeneratedArtifacts
    **/*.DesktopClient/ModelManifest.xml
    **/*.Server/GeneratedArtifacts
    **/*.Server/ModelManifest.xml
    _Pvt_Extensions
    
    # Paket dependency manager
    .paket/paket.exe
    paket-files/
    
    # FAKE - F# Make
    .fake/
    
    # JetBrains Rider
    .idea/
    *.sln.iml
    
    # CodeRush
    .cr/
    
    # Python Tools for Visual Studio (PTVS)
    __pycache__/
    *.pyc

      4.另外需要强调的一点:如果你的项目已经建立Git版本库,那这个时候在添加.gitignore文件后是没有效果的,需要我们手动删除缓存,命令如下:

    git rm -r --cached .

    7.GitHub的使用

      GitHub是基于Git版本控制系统并将项目工程架设到云端进行托管的平台。下面以项目经理和开发人员建立新项目的维度来介绍GitHub的使用流程。

      注:如果是进行演练操作,请自行准备好两个GitHub账号分别对应项目经理和开发人员。

    7.1.在本地使用Git搭建一个代码仓库(项目经理)

    在项目根目录打开Git命令行工具,输入:

    git init

    操作参考图:

       

    7.2.为代码仓库配置自己的用户信息,其中包括用户名和邮箱(项目经理)

    操作参考图:

    7.3.添加并提交项目代码(项目经理)

     操作命令:

    git add *
    git commit -m "注释"

    7.4.GitHub准备工作(项目经理)

    7.4.1.提前注册号账号并登陆GitHub

    7.4.2.在GitHub上创建项目

      操作参考图1:

       操作参考图2:

       操作参考图3:

     至此创建完成。

    7.5.Git配置和操作(项目经理)

    7.5.1.配置远程地址

    操作命令:

    git remote add <远端代号> <远端地址>

    <远端代号> :连接代号。一般直接使用origin作代号,也可以自定义。相当于存储远端地址的变量名称。

    <远端地址> :GitHub项目的Url。

     操作参考图:

     注:以上配置的信息可以在隐藏目录.git下的config文件中查看。

    7.5.2.将项目仓库推送到GitHub

    操作命令:

    git push <远端代号> <本地分支名称>

    输入命令后会提示输入GitHub的用户名和密码

    操作参考图:

     至此推送完毕。

    在GitHub查看推送的结果:

    7.6.从GitHub中将项目以HTTP方式克隆到本地(开发人员)

    7.6.1.选取一个项目存放目录在该目录下打开Git命令行

    输入操作命令:

    git clone <GitHub远程URL>

    操作参考图:

    7.6.2.为项目配置用户信息

    操作参考图:

    7.7.项目功能开发完成后进行新增和提交操作

    操作参考图:

    7.8.在GitHub上设置项目合作人员(项目经理&开发人员)

    7.7.1.要确保进行推送(push)操作的账号具有权限(为GitHub项目邀请合作人员)

     点击绿色按钮进行邀请,邀请后复制用于邀请对方的URL:

     7.7.2.项目经理发送邀请后,开发人员需要将邀请的URL进行访问,在页面中接受邀请。

    操作参考图:

    7.8.推送(开发人员)

    操作命令:

    git push origin master

    操作参考图:

     PS:输入push命令后会要求填写用户名和密码。

     

    7.9.获取(pull)开发人员在GitHub上推送(push)的内容(项目经理)

    操作命令:

    git pull origin master

    操作参考图:

  • 相关阅读:
    Linux 查看CPU个数和磁盘个数
    springboot 文件上传大小配置
    Netty(一):初识Netty
    Java 8里 Stream和parallelStream的区别
    Logstash filter 的使用
    logstash过滤器插件filter详解及实例
    Linux下如何不停止服务,清空nohup.out文件
    logstash收集Nginx日志,转换为JSON格式
    Logstash add_field 参数应用
    Logstash处理json格式日志文件的三种方法
  • 原文地址:https://www.cnblogs.com/green-jcx/p/13622070.html
Copyright © 2011-2022 走看看