git签名设置
作用:只区分不同开发人员的身份
一、项目级别/仓库级别:仅在当前本地库范围内有效
签名设置用户名(UserName)和邮箱(User@email),邮箱可以是任意邮箱(无效邮箱也可以)
1 git config user.name UserName 2 git config user.email User@email
例:用户名xingruyu,邮箱xingruyu@qq.com
zhang@SH-B MINGW64 /c/vm/mygithub (master) $ git config user.name xingruyu zhang@SH-B MINGW64 /c/vm/mygithub (master) $ git config user.email xingruyu@qq.com
信息保存位置:./.git/config 文件 zhang@SH-B MINGW64 /c/vm/mygithub (master) $ ls -al total 8 drwxr-xr-x 1 zhang 1049089 0 2月 3 21:22 ./ drwxr-xr-x 1 zhang 1049089 0 1月 29 23:17 ../ drwxr-xr-x 1 zhang 1049089 0 2月 3 22:12 .git/ zhang@SH-B MINGW64 /c/vm/mygithub (master) $ cat ./.git/config [core] repositoryformatversion = 0 filemode = false bare = false logallrefupdates = true symlinks = false ignorecase = true [user] name = xingruyu email = xingruyu@qq.com zhang@SH-B MINGW64 /c/vm/mygithub (master)
用命令查看用户名和邮箱
zhang@SH-B MINGW64 /c/vm/mygithub (master)
$ git config user.name
xingruyu
zhang@SH-B MINGW64 /c/vm/mygithub (master)
$ git config user.email
xingruyu@qq.com
zhang@SH-B MINGW64 /c/vm/mygithub (master)
二、系统级别:登录当前操作系统的用户范围
1 git config --global user.name UserName 2 git config --global user.email User@email
信息保存位置:~/.gitconfig 文件
zhang@SH-B MINGW64 ~ $ git config --global user.name zhangfei zhang@SH-B MINGW64 ~ $ git config --global user.email zhangfei@email.com zhang@SH-B MINGW64 ~ $ cat .gitconfig [user] name = zhangfei email = zhangfei@email.com
查看
1 git config --global user.name 2 git config --global user.email
级别优先级,就近原则:项目级别优先于系统用户级别,二者都有时采用项目级别的签名
如果只有系统用户级别的签名,就以系统用户级别的签名为准,二者都没有不允许
三、记录git几个命令
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 git rm --cached 文件名 //用于将暂存区的文件恢复到工作区 2 3 zhang@SH-B MINGW64 /c/vm/mygithub (master) 4 $ git add demo 5 warning: LF will be replaced by CRLF in demo/hello.txt. 6 The file will have its original line endings in your working directory 7 8 zhang@SH-B MINGW64 /c/vm/mygithub (master) 9 $ git status 10 On branch master 11 12 No commits yet 13 14 Changes to be committed: 15 (use "git rm --cached <file>..." to unstage) 16 new file: demo/hello.txt 17 18 19 zhang@SH-B MINGW64 /c/vm/mygithub (master) 20 $ git rm --cached demo 21 fatal: not removing 'demo' recursively without -r 22 23 zhang@SH-B MINGW64 /c/vm/mygithub (master) 24 $ git status 25 On branch master 26 27 No commits yet 28 29 Changes to be committed: 30 (use "git rm --cached <file>..." to unstage) 31 new file: demo/hello.txt 32 33 34 zhang@SH-B MINGW64 /c/vm/mygithub (master) 35 $ git rm --cached demo/hello.txt 36 rm 'demo/hello.txt' 37 38 zhang@SH-B MINGW64 /c/vm/mygithub (master) 39 $ git status 40 On branch master 41 42 No commits yet 43 44 Untracked files: 45 (use "git add <file>..." to include in what will be committed) 46 demo/ 47 48 nothing added to commit but untracked files present (use "git add" to track) 49 50 zhang@SH-B MINGW64 /c/vm/mygithub (master) 51 52 53 git commit //文件由缓存区提交到本地库 54 55 zhang@SH-B MINGW64 /c/vm/mygithub (master) 56 57 $ git add demo 58 warning: LF will be replaced by CRLF in demo/hello.txt. 59 The file will have its original line endings in your working directory 60 61 zhang@SH-B MINGW64 /c/vm/mygithub (master) 62 $ git status 63 On branch master 64 65 No commits yet 66 67 Changes to be committed: 68 (use "git rm --cached <file>..." to unstage) 69 new file: demo/hello.txt 70 71 72 zhang@SH-B MINGW64 /c/vm/mygithub (master) 73 $ git commit demo/hello.txt 74 warning: LF will be replaced by CRLF in demo/hello.txt. 75 The file will have its original line endings in your working directory 76 [master (root-commit) 030671e] first commit 77 1 file changed, 1 insertion(+) 78 create mode 100644 demo/hello.txt 79 80 zhang@SH-B MINGW64 /c/vm/mygithub (master) 81 $ git status 82 On branch master 83 nothing to commit, working tree clean 84 85 zhang@SH-B MINGW64 /c/vm/mygithub (master) 86 87 git restore 文件名字 进行清除工作区的改变,与git add 的作用相反 88 89 zhang@SH-B MINGW64 /c/vm/mygithub/demo (master) 90 $ cat hello.txt 91 hello.test 92 modify first 93 94 zhang@SH-B MINGW64 /c/vm/mygithub/demo (master) 95 $ vi hello.txt 96 97 zhang@SH-B MINGW64 /c/vm/mygithub/demo (master) 98 $ cat hello.txt 99 hello.test 100 modify first 101 modify second 102 103 zhang@SH-B MINGW64 /c/vm/mygithub/demo (master) 104 $ git status 105 On branch master 106 Changes not staged for commit: 107 (use "git add <file>..." to update what will be committed) 108 (use "git restore <file>..." to discard changes in working directory) 109 modified: hello.txt 110 111 no changes added to commit (use "git add" and/or "git commit -a") 112 113 zhang@SH-B MINGW64 /c/vm/mygithub/demo (master) 114 $ git restore hello.txt 115 116 zhang@SH-B MINGW64 /c/vm/mygithub/demo (master) 117 $ git status 118 On branch master 119 nothing to commit, working tree clean 120 121 zhang@SH-B MINGW64 /c/vm/mygithub/demo (master) 122 $ cat hello.txt 123 hello.test 124 modify first 125 126 zhang@SH-B MINGW64 /c/vm/mygithub/demo (master) 127 128 git restore --staged <file> //撤销git add 的文件 129 130 MINGW64 /c/vm/mygithub/demo (master) 131 $ git add hello.txt 132 133 zhang@SH-B MINGW64 /c/vm/mygithub/demo (master) 134 $ git status 135 On branch master 136 Changes to be committed: 137 (use "git restore --staged <file>..." to unstage) 138 modified: hello.txt 139 140 141 zhang@SH-B MINGW64 /c/vm/mygithub/demo (master) 142 $ git restore --staged hello.txt 143 144 zhang@SH-B MINGW64 /c/vm/mygithub/demo (master) 145 $ git status 146 On branch master 147 Changes not staged for commit: 148 (use "git add <file>..." to update what will be committed) 149 (use "git restore <file>..." to discard changes in working directory) 150 modified: hello.txt 151 152 no changes added to commit (use "git add" and/or "git commit -a") 153 154 zhang@SH-B MINGW64 /c/vm/mygithub/demo (master)