分類
git 使用紀錄

[git] Personal Access Token

Situation

對 github remote 進行操作時,出現以下錯誤訊息

remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.

簡單的說就是 github密碼驗證在 2021 年 8 月 13 日移除。請改用Personal Acces Token。接下來說明如何產生PAT(Personal Access Token)和如何使用PAT
(也可參考官網)

Action

如何產生PAT

  • 首先登入你的github帳號頁面->點擊右方個人圖示 -> 點擊下方的Settings
  • 在Settings頁面的左欄位的最下方應該有個 Developer settings,點擊它!
  • 在Developer Settings頁面的左欄位應該有個 Personal access tokens,點擊它!
  • 這裡就是Personal Access Token頁面,可以在這裡進行PAT的相關操作
    (點擊 Generate new token)
  • 在Note填入相關資訊 / 在Expiration選擇有效期限 / 在Select scopes 勾選 scopes
  • 最後勾選最下方的 Generate token
  • 自動回到Personal access Token頁面,有個綠底打勾的字串,請把它複製保存好(離開這個頁面後就不再出現了)

如何使用PAT

基本上PAT就是用來取代操作 github remote時密碼的作用。輸入密碼的位置改輸入PAT的內容即可!

Result

git remote 的操作可以成功進行,不再出現Situation的錯誤訊息

分類
ASP.NET git 使用紀錄 Web 前端

在ASP.NET Webform專案中加入專屬的 gitignore file

不用到處搜尋 .gitignore 檔案啦,先移動到專案的根目錄再輸入以下指令


dotnet new gitignore

就會在根目錄產生 .gitignore file,內容如下


## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# Tye
.tye/
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.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
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Coverlet is a free, cross platform Code Coverage Tool
coverage*[.json, .xml, .info]
# Visual Studio code coverage results
*.coverage
*.coveragexml
# 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
# Note: 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
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable 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
*.appx
*.appxbundle
*.appxupload
# 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
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# 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
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# 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/
# Ionide - VsCode extension for F# Support
.ionide/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
##
## Visual studio for Mac
##
# globs
Makefile.in
*.userprefs
*.usertasks
config.make
config.status
aclocal.m4
install-sh
autom4te.cache/
*.tar.gz
tarballs/
test-results/
# Mac bundle stuff
*.dmg
*.app
# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk
# JetBrains Rider
.idea/
*.sln.iml
##
## Visual Studio Code
##
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

至於 dotnet 只是啥
請參考 https://docs.microsoft.com/zh-tw/dotnet/core/tools/dotnet

分類
git 使用紀錄

git 建立自定義指令(git customize command)

使用 git branch 指令建立 branch 有個小缺點,就是branch name 不可以摻雜空格。e.g.

git branch branchname can not contain space

就會出現以下提示

usage: git branch [options] [-r | -a] [--merged | --no-merged]
   or: git branch [options] [-l] [-f] <branchname> [<start-point>]
   or: git branch [options] [-r] (-d | -D) <branchname>...
   or: git branch [options] (-m | -M) [<oldbranch>] <newbranch>
Generic options
    -v, --verbose         show hash and subject, give twice for upstream branch
    -t, --track           set up tracking mode (see git-pull(1))
    --set-upstream        change upstream info
    --color[=<when>]      use colored output
    -r, --remotes         act on remote-tracking branches
    --contains <commit>   print only branches that contain the commit
    --abbrev[=<n>]        use <n> digits to display SHA-1s
Specific git-branch actions:
    -a, --all             list both remote-tracking and local branches
    -d, --delete          delete fully merged branch
    -D                    delete branch (even if not merged)
    -m, --move            move/rename a branch and its reflog
    -M                    move/rename a branch, even if target exists
    --list                list branch names
    -l, --create-reflog   create the branch's reflog
    --edit-description    edit the description for the branch
    -f, --force           force creation (when already exists)
    --no-merged <commit>  print only not merged branches
    --merged <commit>     print only merged branches

 
搜尋了一下似乎沒有很直觀的解決方式。決定使用客製化 git 指令的方式來解決。
客製化指令其實相當簡單。
只有2個步驟,
1.建立指令檔案。
2.將指令檔案加到PATH環境變數中。


 
我的目標為自動把branch name的空格轉換為底線。e.g.
當我輸入(xxx為 git 自定義指令名稱)

git xxx branchname can not contain space

該指令會建立一個branch轉換為 branchname_can_not_contain_space,等同於輸入

git branch branchname_can_not_contain_space

 
首先
1.建立指令檔案,使用shell script來完成。
這裡要注意命名規則,指令檔案必須以 git- 開頭,後面接上你想取的名字,不需要副檔名。
以本範例來說我把它命名為 git-branchbaseline

#!/bin/bash
concat_parameters_with_baseline()
{
finalName=$@
for var in "$@"
do
finalName=${finalName/ /_}
done
echo create new branch, name:$finalName
git branch $finalName
}
concat_parameters_with_baseline $@

然後需要開放git-branchbaseline 的權限。
輸入

sudo chmod /complete/path/of/git-branchbaseline 777

 
2.考慮到之後可能會建立其他客製化指令,建立專門存放指令的資料夾在 /complete/path/of/git_customize_commands,並放入剛剛的git-branchbaseline。
將資料夾加到環境變數PATH

export PATH=$PATH:/complete/path/of/git_customize_commands

 
Update 20160622!!!
export 方式只能對目前開啟的的 Terminal 有作用,如果希望環境變數維持有效可以考慮修改 ~/.bashrc (使用bash的情況)。
因為我用的是zsh,所以需要修改 ~/.zshrc,開啟~/.zshrc 並加入

export PATH=$PATH:/complete/path/of/git_customize_commands

 
完成!!!
接著只要到 git repo 測試新指令即可。

git branchbaseline branchname can not contain space

 
 
 

分類
Android git 使用紀錄 Jenkins Uncategorized

合併 Jenkins 和 GitHub for Andriod Project

Jenkins 除了可以和 Local 端專案整合,也可和github一起工作。
這篇紀錄如何整合jenkins和github。
1.先在github上建立空專案。
2.在Build Server(jenkins),先 git clone github下來,並建立 android project,注意要使用 ant 成功建立專案(ant release or ant debug),
注意,不要加入local.properties 和 ant.properties,可以加入.gitignore來忽略。
完成後git push到github上
3.在jenkins建立專案並設定git path為github的路徑。
4.若有需要先在github上merge第3步驟的push commit,完成後jenkins 可以build成功。
其他詳細可參考 https://wiki.jenkins-ci.org/display/JENKINS/Building+an+Android+app+and+test+project

分類
git 使用紀錄

Git : 無法加入檔案( Can't git add file)

Description : 

當在git project 底下,若有些檔案無法加入(git add),很有可能是被 git ignore了。
詳細說明參考這篇(http://stackoverflow.com/questions/1084969/unable-to-track-files-within-git-submodules)
以下節錄相關的說明
大部分的情況下,檔案被 git ignore,有2個主要原因:.gitignore submodule
.gitignore 是一個說明檔和 .git 位於同一層,主要的用途就是忽略不需要追蹤的檔案。
android project 為例,當進行clean build 的動作都會讓bin/ 資料夾內的檔案重新生成。
這些重新生成的檔案多半是不需要追蹤,因此就能藉由 .gitignore 說明檔來描述哪些檔案不需要追蹤。
以下為簡單的範例
這是剛建立完成android project並初始化 git(git init)的情況。可以看到 bin/ 資料夾。

# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	.classpath
#	.project
#	AndroidManifest.xml
#	bin/
#	gen/
#	ic_launcher-web.png
#	libs/
#	proguard-project.txt
#	project.properties
#	res/
#	src/

接著建立 .gitignore 檔案。
vim .gitignore 並填入 bin/ bin/ 的意思為忽略 bin/ 內所有檔案)
再輸入 git status 觀察,可以看到多了.gitignore ,少了bin/

# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	.classpath
#	.gitignore
#	.project
#	AndroidManifest.xml
#	gen/
#	ic_launcher-web.png
#	libs/
#	proguard-project.txt
#	project.properties
#	res/
#	src/

此即為第一種 git ignore 的情況,若直接輸入 git add bin/ git 會說明情況

The following paths are ignored by one of your .gitignore files:
bin
Use -f if you really want to add them.
fatal: no files added

強制加入請輸入 git add –force bin/

# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#	new file:   bin/AndroidManifest.xml
#	new file:   bin/R.txt
#	new file:   bin/classes/android/support/v7/appcompat/R$anim.class
#	new file:   bin/classes/android/support/v7/appcompat/R$attr.class
#	new file:   bin/classes/android/support/v7/appcompat/R$bool.class
#	new file:   bin/classes/android/support/v7/appcompat/R$color.class
#	new file:   bin/classes/android/support/v7/appcompat/R$dimen.class
#	new file:   bin/classes/android/support/v7/appcompat/R$drawable.class
#	new file:   bin/classes/android/support/v7/appcompat/R$id.class
...

 
2種情況為 submodule
這種情況比較複雜一些,必須進行4個步驟。
Note : 注意這4個步驟可能會毀損 git repo,若不確定情況,可以先試試第3步驟。
1. .gitmodule中刪除相關的連結
2. .git/config中刪除相關的連結
3. 執行 git rm –cached path_to_submodule

rm 'path_to_submodule'

4. 執行 git commit

a[master 5c270a9] [xxxx] Remove file in submodule.
 1 file changed, 1 deletion(-)
 delete mode 160000 path_to_submodule

 
 
 

分類
git 使用紀錄

Git : 如何取消已經追蹤的檔案(set file to untracked)

Description:
android project 為例,大多數的情況下,不需要追蹤 /bin 資料夾裡的檔案。但若已經將bin資料夾加入追蹤。要如何讓 bin 回到 untrack 的狀態?
 
Solution:
1.移動到 project 根目錄下輸入
git rm –cached -r bin

rm 'bin/AndroidManifest.xml'
rm 'bin/R.txt'
rm 'bin/classes/android/support/v7/appcompat/R$anim.class'
rm 'bin/classes/android/support/v7/appcompat/R$attr.class'
rm 'bin/classes/android/support/v7/appcompat/R$bool.class'
rm 'bin/classes/android/support/v7/appcompat/R$color.class'
rm 'bin/classes/android/support/v7/appcompat/R$dimen.class'
rm 'bin/classes/android/support/v7/appcompat/R$drawable.class'
rm 'bin/classes/android/support/v7/appcompat/R$id.class'
rm 'bin/classes/android/support/v7/appcompat/R$integer.class'
rm 'bin/classes/android/support/v7/appcompat/R$layout.class'
rm 'bin/classes/android/support/v7/appcompat/R$string.class'
rm 'bin/classes/android/support/v7/appcompat/R$style.class'
...

 
2.
commit 該動作。(git commit)

[master 846ecc5] [Test] Ignore all files in /bin folder.
 31 files changed, 620 deletions(-)
 delete mode 100644 bin/AndroidManifest.xml
 delete mode 100644 bin/R.txt
 delete mode 100644 bin/classes/android/support/v7/appcompat/R$anim.class
 delete mode 100644 bin/classes/android/support/v7/appcompat/R$attr.class
 delete mode 100644 bin/classes/android/support/v7/appcompat/R$bool.class
 delete mode 100644 bin/classes/android/support/v7/appcompat/R$color.class
 delete mode 100644 bin/classes/android/support/v7/appcompat/R$dimen.class
 delete mode 100644 bin/classes/android/support/v7/appcompat/R$drawable.class
 delete mode 100644 bin/classes/android/support/v7/appcompat/R$id.class
 delete mode 100644 bin/classes/android/support/v7/appcompat/R$integer.class
 delete mode 100644 bin/classes/android/support/v7/appcompat/R$layout.class
 delete mode 100644 bin/classes/android/support/v7/appcompat/R$string.class
 delete mode 100644 bin/classes/android/support/v7/appcompat/R$style.class
 delete mode 100644 bin/classes/android/support/v7/appcompat/R$styleable.class
...

 
3.
使用 git status 查詢,可以看到 bin 資料夾已經回到 untracked 狀態。

# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	bin/
nothing added to commit but untracked files present (use "git add" to track)

 

分類
git 使用紀錄

更新 Git 版本

主要原因是建置 Android Build 環境時, repo 的初始化需要 git 1.7.2以上的版本,必須升級 git
方法:
終端機輸入

sudo apt-add-repository ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git-core

即可更新 git 版本

分類
git 使用紀錄

Git 使用記錄(移除檔案+更改檔名)

1.移除檔案
在一個容器中新增檔案時,此檔案會被歸類於未追蹤
我們新增一個文件叫 testrm 來試試看,輸入

echo 'test in rm' > testrm
git status

 

的確是在未追蹤,現在我們把它加入容器中(改變狀態為已加入)
輸入

git add testrm

如果這時候想把它從已加入去除的話,輸入

git rm --cached

OK~ 看起來是從已加入去除了,不過為了保險起見,還是輸入 git status 看看

git status

testrm 的確回復到未追蹤的狀態
那如果檔案已加入而且已被提交,如何從容器中去除?
再次把 testrm 加入並提交,輸入

git add testrm
git commit -m "commit testrm"

到此 testrm 已被提交,從已提交中移除需要2個步驟
第ㄧ種情況想保留 testrm 檔案,單純的想從容器中移出,輸入

git rm --cached testrm

再輸入

git commit -m "delete testrm"

如此檔案本身存在只是會被移出容器
第二種情況如果想連檔案本身一起移除的話,輸入

git rm testrm

到此,觀察資料夾雖然可以看到 testrm 已經不存在,但還是要提交,輸入

git commit -m "delete testrm"

現在 testrm 不但被移出容器外且本身也不存在
2.更改檔名
先新增一個檔案為 testmv ,輸入

echo 'test_mv' > testmv

更改檔名只能在已加入的狀態修改,所以先把它加入吧,輸入

git add testmv

更改檔名的格式為 git mv 原檔名 新檔名 ,輸入

git mv testmv testmv2

在資料夾中可以看到 testmv 已經變成 testmv2 了
不過輸入 git status 看看,會提示必須提交才算完成

git status

輸入

git commit -m "rename testmv to testmv2"
git status

可以看到更名的步驟已經提交完成

至於已經提交檔案的更名步驟也是相同,必須先輸入更名的指令,再提交

分類
git 使用紀錄

Git 使用記錄(初始化容器+複製外部容器+加入檔案+觀察容器檔案內容+觀察檔案差異+提交檔案+觀察提交檔案內容)

1.初始化容器
選擇想要的資料夾當作容器,在家目錄中新建資料夾 Git_Project 為範例
開啓終端機,輸入

cd ~
mkdir Git_Project
cd Git_Project
echo 'test in git' > testword

到此完成 Git_Project 資料夾和 以 test in git 為內容的 testword 文件建立
接著輸入

git init

指定以目前資料夾(Git_Project)為容器
2.複製外部容器
這裡以 google code 為例
輸入

git clone https://0000foxx@code.google.com/p/foxx-gitproject-gittest/

也可以指定名稱(dir_name)
輸入

git clone https://0000foxx@code.google.com/p/foxx-gitproject-gittest/  dir_name

2.1 使用 git ssh clone

git clone ssh://username@xxx.xxx.xxx.xxx/home/username/absolute/path

 
3.加入檔案

git add testword

如果檔案中有許多資料想全部加入追蹤,輸入

git add .

4.觀察容器檔案狀態
輸入

git status

如果照著以上步驟作的話會得到以下畫面

顯示我們在  master 的 branch 上, testword 檔案將會在下次提交的時候記錄起來
接著修改 testword 內容為
test in git 2
再輸入 git status 看看

git status

git 很好心的提示我們 testword 已經被修改了,需要重新 add 才行,輸入

git add testword
git status

OK~ 修改的部分也已經加入了
5.觀察檔案差異
剛剛使用 git status 只會顯示已被修改,若想進一步觀察修改了哪些內容可以使用 git diff
修改 testword 內容為
test in git 3
接著輸入

git diff

上次修改和目前的差異,注意 git diff 只能顯示還未 add 的差異,如果要比較已經提交和目前的差異要用 git diff –cached 或 git diff –staged
6.提交檔案
輸入

git commit

提交時必須輸入註解訊息,如果是用 vim 先按 a ,下方的提示會顯示 INSERT ,再輸入註解訊息完成後,先按 esc 再按 :wq
提交完成會得到以下畫面

可以得知在哪個 branch(master) 上,以及註解內容等等
再次輸入

git status

(可以看到已經沒有東西可以提交)

7.觀察提交檔案內容
想要知道最近提交的內容,可以使用 git log 或 git show
輸入

git log

(會顯示每個提交的內容,識別碼)

git show 可以附註識別碼來指定觀察
輸入

git show 4941f8fbb701c41f71da7dd70653b43ced98d40f

可以看到提交檔案更詳細的內容

分類
git 使用紀錄

Git 使用記錄 (下載Git+安裝Git+設定配置姓名和Email)

1.安裝git
直接到官網下載安裝,除了 Mac/Windows 使用安裝檔(dmg/exe),其他的都用指令安裝
2.測試git
開啓終端機,輸入

git

順利的話會得到類似以下畫面的回應,代表已經安裝完成

來看看目前版本,輸入

git --version

會顯示安裝版本

3.設定個人訊息
在提交檔案之前先來設定 個人訊息 的配置,包含名字和E-mail
輸入

git config user.name "your_name"
git config user.email "your_email"

如果出現

error: could not lock config file .git/config: No such file or directory

 
請加入 –global

git config --global user.name "your_name"
git config --global user.email "your_email"

之後提交檔案都會使用這組個人訊息,當然想重新設定也是沒問題
可以使用 git config –list 來查看個人訊息

想要查詢指令如何使用,輸入
git help 指令

git help config