Git 常用指令(Git Tips)

Ping-Lun Liao
1 min readOct 17, 2019

--

此篇記錄筆者常用的Git指令。

Configuration相關

git config — global user.name “username”
git config — global user.email “username@mail.domain.address”
git config — global core.editor vim

# Line Ending
git config — global core.autocrlf input
git config — global core.safecrlf true

# Color Highlighting

git config core.sharedRepository group
git repo-config core.sharedRepository group

git config — global http.proxy http://proxyuser:proxypwd@proxy.server.com:8080
git config — global https.proxy http://proxyuser:proxypwd@proxy.server.com:8080

Backup a git repository (The quick and easy way)

git bundle create bundleName/Path/To branch_name
git bundle create /tmp/foo master
git bundle create /tmp/foo-all — all (for all branch)

git bundle list-heads /tmp/foo
git bundle list-heads /tmp/foo-all
git bundle verify bundle_name

Restoring a git repository

git clone bundle_name repo_Destination_Path branch_name
git clone bundle_name repo_Destination_Path -b master (with source code)
git clone — bare bundle_name repo_Destination_Path -b master (for bare repository no source code)

Restore a file from a specific commit

git checkout [commit_id] file/to/restore

Untracked a file

git rm — cached filePath

Delete commit

git reset — soft
git reset — hard

=========================================================================
View the change history of an individual file

gitk [filename]
git log — [filename]
git rm -r — cached <your directory>

Checking status

Originally published at https://yunlinsong.blogspot.com.

--

--

No responses yet