1. 程式人生 > >git config配置,工作區和版本庫聯系。

git config配置,工作區和版本庫聯系。

linu htm 相關 lfs global intro git bash .text desktop

關於git和github的介紹,我這邊不多說。

使用在windows下使用git,需要配置環境變量,也可以使用git自帶的終端工具。技術分享,打開git bash

[email protected] MINGW64 ~ (master)
$ cd c:/laoni

[email protected]-TPPLHIB MINGW64 /c/laoni
$ dir
AutomatedMonitor  bak  Mr.blue  PycharmProjects

[email protected]-TPPLHIB MINGW64 /c/laoni
$ cd PycharmProjects
/

界面和linux的終端相識,首先需要進行初始化,也就是配置個人信息:

使用git help可以查看git相關命令,也可以通過git help command指定命令查詢。

技術分享
$ git help
usage: git [--version] [--help] [-C <path>] [-c name=value]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
           [
--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>] <command> [<args>] These are common Git commands used in various situations: start a working area (see also: git help tutorial) clone Clone a repository into a new directory init Create an empty Git repository or reinitialize an existing one work on the current change (see also: git help everyday) add Add
file contents to the index mv Move or rename a file, a directory, or a symlink reset Reset current HEAD to the specified state rm Remove files from the working tree and from the index examine the history and state (see also: git help revisions) bisect Use binary search to find the commit that introduced a bug grep Print lines matching a pattern log Show commit logs show Show various types of objects status Show the working tree status grow, mark and tweak your common history branch List, create, or delete branches checkout Switch branches or restore working tree files commit Record changes to the repository diff Show changes between commits, commit and working tree, etc merge Join two or more development histories together rebase Reapply commits on top of another base tip tag Create, list, delete or verify a tag object signed with GPG collaborate (see also: git help workflows) fetch Download objects and refs from another repository pull Fetch from and integrate with another repository or a local branch push Update remote refs along with associated objects git help -a and git help -g list available subcommands and some concept guides. See git help <command> or git help <concept> to read about a specific subcommand or concept.
git help

使用git config --global user.name "XXX" 和git config --global user.email "[email protected]"可以添加用戶名和郵箱,

使用 git config --unset --global user.name 可以取消用戶名配置,

使用 git config --list 查看所有可用的配置信息。

技術分享
[email protected] MINGW64 /c/laoni/PycharmProjects/github_test
$ git config --global user.name LaoNiNi

[email protected]-TPPLHIB MINGW64 /c/laoni/PycharmProjects/github_test
$ git config --global user.email "[email protected]"

[email protected]-TPPLHIB MINGW64 /c/laoni/PycharmProjects/github_test
$ git config --unset --global user.name

[email protected]-TPPLHIB MINGW64 /c/laoni/PycharmProjects/github_test
$ git config --list
core.symlinks=false
core.autocrlf=true
core.fscache=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
help.format=html
rebase.autosquash=true
http.sslcainfo=F:/pythonfile/Git/mingw64/ssl/certs/ca-bundle.crt
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.required=true
filter.lfs.process=git-lfs filter-process
credential.helper=manager
user.email=laonivv@163.com
filter.lfs.clean=git-lfs clean %f
filter.lfs.smudge=git-lfs smudge %f
filter.lfs.required=true
git config

git區分工作區和版本庫

技術分享

對於項目更目錄github_test目錄來說,這就是工作區。

使用 git init 命令進行初始化,之前的config配置,需要初始化才能生效,config配置信息存在.git/config文件

[email protected] MINGW64 /c/laoni/PycharmProjects/github_test
$ git init
Initialized empty Git repository in C:/laoni/PycharmProjects/github_test/.git/

PS:如果對git不熟悉的話,建議不要對。git目錄下的文件進行修改。

使用git status查看當前git狀態,Untracked files(未監視的文件,未被跟蹤文件)也就是沒有存到暫存區(上面截圖的版本庫下的index部分)的文件,使用git add index.html 把文件添加到暫存區。

[email protected] MINGW64 /c/laoni/PycharmProjects/github_test (master)
$ git status
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        index.html

nothing added to commit but untracked files present (use "git add" to track)

[email protected]-TPPLHIB MINGW64 /c/laoni/PycharmProjects/github_test (master)

[email protected] MINGW64 /c/laoni/PycharmProjects/github_test (master)
$ git add index.html

[email protected] MINGW64 /c/laoni/PycharmProjects/github_test (master)
$ git status
On branch master

Initial commit

Changes to be committed:
(use "git rm --cached <file>..." to unstage)

new file: index.html

把index.html文件添加到暫存區後,需要把文件從暫存區添加到branch master分支上,一般一個項目會有個主分支(一般叫master),使用git commit提交,會提示說明下這次的提交註釋,再用git status查看,提示在當前主分支,沒有需要commit的文件,工作區很幹凈。

[email protected] MINGW64 /c/laoni/PycharmProjects/github_test (master)
$ git commit
[master (root-commit) 04c94a8] 添加一個文件index.html
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 index.html

laoni@DESKTOP-TPPLHIB MINGW64 /c/laoni/PycharmProjects/github_test (master)
$ git status
On branch master
nothing to commit, working tree clean

實際上不管是暫存區還是分支上的文件,都存儲在objects裏面,暫存區和分支上的文件只是一個指向,目錄樹,有點像windows裏的快捷方式了,這個需要理清。

git config配置,工作區和版本庫聯系。