最近工作中用到git,其实之前也用过,但是忘的差不多了。现在再来复习一下。
参考了廖老师的网站。
我的使用的是2019最新版13.3寸的MacBook Pro。系统是10.15.1。
chens-MacBook-Pro:~ chenchen$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.15.1
BuildVersion: 19B88
chens-MacBook-Pro:~ chenchen$
先百度git,第一个结果是git官网,点击进入。
进入如下页面,选左下角 Download,进入新页面。
然后选对应的操作系统,我选Mac OS X,
然后,会下载一个dmg文件,下载成功后,双击安装一步步进行下去直到完成即可。
同时你还可以下载git的pdf教程。
可以在terminal里输入git 然后回车。如果显示内容如下所示,则安装成功。
使用 git init,这时会看到当前目录下出现 .git 。
chens-MacBook-Pro:~ chenchen$ ls
Desktop Downloads Movies Pictures
Documents Library Music Public
chens-MacBook-Pro:~ chenchen$ pwd
/Users/chenchen
chens-MacBook-Pro:~ chenchen$ mkdir learn_git
chens-MacBook-Pro:~ chenchen$ pwd
/Users/chenchen
chens-MacBook-Pro:~ chenchen$ cd learn_git/
chens-MacBook-Pro:learn_git chenchen$ pwd
/Users/chenchen/learn_git
chens-MacBook-Pro:learn_git chenchen$ git init
Initialized empty Git repository in /Users/chenchen/learn_git/.git/
chens-MacBook-Pro:learn_git chenchen$ ls -al
total 0
drwxr-xr-x 3 chenchen staff 96 Nov 30 18:36 .
drwxr-xr-x+ 21 chenchen staff 672 Nov 30 18:35 ..
drwxr-xr-x 10 chenchen staff 320 Nov 30 18:36 .git
第三步,现在你就可以在刚才init的目录里新建文本文件,然后提交了。
git add是把工作区的修改,添加到暂存区。
git commit是把暂存区的修改提交到master分支。
下面展示的是
chens-MacBook-Pro:learn_git chenchen$ vi readme
chens-MacBook-Pro:learn_git chenchen$ cat readme
Git is a distributed version control system.
Git is free software distributed under the GPLadd fourth
chens-MacBook-Pro:learn_git chenchen$ git status
On branch master
Changes not staged for commit:(use "git add <file>..." to update what will be committed)(use "git restore <file>..." to discard changes in working directory)modified: readmeno changes added to commit (use "git add" and/or "git commit -a")
chens-MacBook-Pro:learn_git chenchen$ git add readme
chens-MacBook-Pro:learn_git chenchen$ git status
On branch master
Changes to be committed:(use "git restore --staged <file>..." to unstage)modified: readmechens-MacBook-Pro:learn_git chenchen$ git commit -m" add fourth"
[master ff3af09] add fourthCommitter: chen chen <chenchen@chens-MacBook-Pro.local>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:git config --global --editAfter doing this, you may fix the identity used for this commit with:git commit --amend --reset-author1 file changed, 2 insertions(+)
chens-MacBook-Pro:learn_git chenchen$ git status
On branch master
nothing to commit, working tree clean
chens-MacBook-Pro:learn_git chenchen$
从上面可以看到不同状态下,git status会输出什么。
比如添加了文件,但是没有git add。或者git add了,但是没有git commit。以及最后git commit了,输出git status会有什么。<
本文发布于:2024-02-04 06:00:26,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170700556152900.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |