git 文件三种状态:
以修改
以暂存
已提交
master 主分支 在mater分支中发布项目 (master分支是默认的分支)
mkdir myGit #创建myGit文件
cd myGit #进入myGit
git init # 初始化git
Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ cd .git
Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$ ll
total 7
-rw-r--r-- 1 Administrator 197121 130 八月 20 21:09 config
-rw-r--r-- 1 Administrator 197121 73 八月 20 21:09 description
-rw-r--r-- 1 Administrator 197121 23 八月 20 21:09 HEAD
drwxr-xr-x 1 Administrator 197121 0 八月 20 21:09 hooks/
drwxr-xr-x 1 Administrator 197121 0 八月 20 21:09 info/
drwxr-xr-x 1 Administrator 197121 0 八月 20 21:09 objects/
drwxr-xr-x 1 Administrator 197121 0 八月 20 21:09 refs/
Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ touch test.txt
Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ ll
total 0
-rw-r--r-- 1 Administrator 197121 0 八月 20 21:35 test.txt
Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ vim test.txt
Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ cat test.txt
i love you_01
Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ git status
On branch master
No commits yet
Untracked files:
(use "git add ..." to include in what will be committed)
test.txt
nothing added to commit but untracked files present (use "git add" to track)
Administrator@kevin MINGW32 ~/Desktop/myGit (master)
Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ git add test.txt
warning: LF will be replaced by CRLF in test.txt.
The file will have its original line endings in your working directory
Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached ..." to unstage)
new file: test.txt
Administrator@kevin MINGW32 ~/Desktop/myGit (master)
git文件从暂存区回退到以修改状态:git rm 命令
$ git rm test.txt
error: the following file has changes staged in the index:
test.txt
(use --cached to keep the file, or -f to force removal)
Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached ..." to unstage)
new file: test.txt
Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$
git commit必须写注释否则:
格式: git commit -m ‘注释’
$ git commit
*** Please tell me who you are.
Run
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'Administrator@kevin.(none)')
Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ git commit -m '测试'
*** Please tell me who you are.
Run
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'Administrator@kevin.(none)')
Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$
对于user.name 与user.email来说有三个地方可以设置
$ git config
usage: git config []
Config file location
--global use global config file
--system use system config file
--local use repository config file
Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ git config --global user.name 'zx'
Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ git config --global user.email '[email protected]'
Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$
$ git commit -m '测试'
[master (root-commit) ba82baf] 测试
1 file changed, 1 insertion(+)
create mode 100644 test.txt
Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ git status
On branch master
nothing to commit, working tree clean
Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$
Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ git config
usage: git config []
Config file location
--global use global config file
--system use system config file
--local use repository config file
--worktree use per-worktree config file
-f, --file use given config file
--blob read config from given blob object
Action
--get get value: name [value-regex]
--get-all get all values: key [value-regex]
--get-regexp get values for regexp: name-regex [value-regex]
--get-urlmatch get value specific for the URL: section[.var] URL
--replace-all replace all matching variables: name value [value_regex]
--add add a new variable: name value
--unset remove a variable: name [value-regex]
--unset-all remove all matches: name [value-regex]
--rename-section rename section: old-name new-name
--remove-section remove a section: name
-l, --list list all
-e, --edit open an editor
--get-color find the color configured: slot [default]
--get-colorbool find the color setting: slot [stdout-is-tty]
Type
-t, --type <> value is given this type
--bool value is "true" or "false"
--int value is decimal number
--bool-or-int value is --bool or --int
--path value is a path (file or directory name)
--expiry-date value is an expiry date
Other
-z, --null terminate values with NUL byte
--name-only show variable names only
--includes respect include directives on lookup
--show-origin show origin of config (file, standard input, blob, command line)
--default with --get, use default value when missing entry
Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$
Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$ ll
total 9
-rw-r--r-- 1 Administrator 197121 7 八月 20 22:06 COMMIT_EDITMSG
-rw-r--r-- 1 Administrator 197121 148 八月 20 22:10 config
-rw-r--r-- 1 Administrator 197121 73 八月 20 21:09 description
-rw-r--r-- 1 Administrator 197121 23 八月 20 21:09 HEAD
drwxr-xr-x 1 Administrator 197121 0 八月 20 21:09 hooks/
-rw-r--r-- 1 Administrator 197121 137 八月 20 21:45 index
drwxr-xr-x 1 Administrator 197121 0 八月 20 21:09 info/
drwxr-xr-x 1 Administrator 197121 0 八月 20 22:06 logs/
drwxr-xr-x 1 Administrator 197121 0 八月 20 22:06 objects/
drwxr-xr-x 1 Administrator 197121 0 八月 20 21:09 refs/
Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$ cat config
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[user]
name = zz
Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$ git config --local user.name 'zx'
Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$ git config --local user.email '[email protected]'
Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$ cat config
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[user]
name = zx
email = [email protected]
Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$ git config -l
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=d:/Program Files/Git/mingw32/ssl/certs/ca-bundle.crt
http.sslbackend=openssl
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge --skip -- %f
filter.lfs.process=git-lfs filter-process --skip
filter.lfs.required=true
pack.packsizelimit=2g
add.interactive.usebuiltin=true
user.name=zx
[email protected]
core.repositoryformatversion=0
core.filemode=false
core.bare=false
Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$ git config user.name
zx
Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$ git config user.email
[email protected]
Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$
Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$ git config --local user.name 'zdd'
Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$ git config --local --unset user.name
Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$ cat config
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[user]
email = [email protected]
Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$ git config --local user.name 'zx'
Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$ git config user.name
zx
Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$ git config user.email
[email protected]
Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
$ cat config
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[user]
email = [email protected]
name = zx
Administrator@kevin MINGW32 ~/Desktop/myGit/.git (GIT_DIR!)
Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ cat ~/.gitconfig
[user]
name = zx
email = [email protected]
Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$
$ echo 'i love you to'>test.txt
Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ cat test.txt
i love you to
Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ git status
On branch master
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git restore ..." to discard changes in working directory)
modified: test.txt
no changes added to commit (use "git add" and/or "git commit -a")
Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ git add test.txt
warning: LF will be replaced by CRLF in test.txt.
The file will have its original line endings in your working directory
Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ git commit -m '再次修改为 iloveyou to'
[master 9b79eb7] 再次修改为 iloveyou to
1 file changed, 1 insertion(+), 1 deletion(-)
Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ cat test.txt
i love you to
Administrator@kevin MINGW32 ~/Desktop/myGit (master)
$ git log
commit 9b79eb743639cfd7b6e62966d6012403ce3b3fd0 (HEAD -> master)
Author: zx
Date: Tue Aug 20 22:24:52 2019 +0800
再次修改为 iloveyou to
commit ba82bafa862d0cccdd105e725f2e17f711a321eb
Author: zx <[email protected]>
Date: Tue Aug 20 22:06:58 2019 +0800
测试
Administrator@kevin MINGW32 ~/Desktop/myGit (master)