设置用户签名
git config --global user.name 用户名
git config --global user.email 邮箱
说明: 签名的作用是区分不同操作者身份。用户的签名信息在每一个版本的提交信息中能够看 到,以此确认本次提交是谁做的。Git 首次安装必须设置一下用户签名,否则无法提交代码。
※注意:这里设置用户签名和将来登录 GitHub(或其他代码托管中心)的账号没有任何关系。
初始化本地库
git init
说明:初始化本地库会生成一个.git的隐藏文件夹,可通过ll -a来查看隐藏文件夹。
查看本地库状态
git status
说明:查看本地库状态有三行信息,第一行是所在的分支,第二和第三行是提交的信息
例子1(没有文件可以追踪到暂存区):
$ git status
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)
例子2(检测到未追踪的文件):
$ git status
On branch master
No commits yet
Untracked files:
(use "git add ..." to include in what will be committed)
hello.txt
nothing added to commit but untracked files present (use "git add" to track)
例子3(检测到暂存区有新文件):
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached ..." to unstage)
new file: hello.txt
添加到暂存区
git add 文件名
※注意:
warning: LF will be replaced by CRLF in hello.txt.
是因为Git的换行符检查功能,LF是linux下的换行符,而CRLF是enter + 换行。
Git提供了一个换行符检查功能(core.safecrlf),可以在提交时检查文件是否混用了不同风格的换行符。