配置全域忽略檔案.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
操作參考圖:

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/1003.html
標籤:其他
上一篇:Git&GitHub學習和運用(2.分支管理和沖突解決)
下一篇:專案微管理39 - 懲罰
