git repo入门操作学习笔记

CSDN上写GIT工具的优质博客很多,本来我也想边学习便总结输出下,但是看到人家的博文珠玉在前,便下不去笔了,下面是我按照下篇优质博文的描述进行操作练习的笔记
git使用教程

git基本操作

git init

初始化某个当前的目录,变成Git可以管理的仓库

wangkexing@sh-48-152:~/Vaccine_work/helloworld$ git init 
Initialized empty Git repository in /data/wangkexing/Vaccine_work/helloworld/.git/

然后该helloworld目录下,就有一个.git的隐藏目录。这个目录是Git来跟踪管理版本库的。如下

wangkexing@sh-48-152:~/Vaccine_work/helloworld$ la
.git  helloworld.c

此时使用git status查看当前的状态如下

wangkexing@sh-48-152:~/Vaccine_work/helloworld$ git status
On branch master

Initial commit

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

	helloworld.c

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

wangkexing@sh-48-152:~/Vaccine_work/helloworld$ git add helloworld.c 
wangkexing@sh-48-152:~/Vaccine_work/helloworld$ git status
On branch master

Initial commit

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

	new file:   helloworld.c

wangkexing@sh-48-152:~/Vaccine_work/helloworld$ git commit
[master (root-commit) ee922e2] Initial commit of helloworld project
 1 file changed, 6 insertions(+)
 create mode 100644 helloworld.c

git commit -m “添加的提交注释” [filename]

这里filename可加可不加,加上说明是提交filename指定的文件,不加则表示提交暂存区中所有修改的内容,提交之后,然后再查看状态如下:

wangkexing@sh-48-152:~/Vaccine_work/helloworld$ git status
On branch master
nothing to commit, working directory clean

撤销修改

  • 当有文件被修改时候,如果没有使用git add命令添加到暂存区,此时查看git status时候,如下提示
wangkexing@sh-48-152:~/Vaccine_work/helloyou$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	modified:   helloyou.c

no changes added to commit (use "git add" and/or "git commit -a")

此时想撤销修改,有两种方法

  1. 如果方便的话,打开修改的文件,把修改的文件手动删除
  2. 或者是 执行 git checkout – filename
  • 如果修改的文件已经使用git add 命令添加到暂存区上了,先看一下状态
wangkexing@sh-48-152:~/Vaccine_work/helloyou$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

	modified:   helloyou.c

此时若想撤销修改,先使用git reset HEAD helloyou.c ,操作如下

wangkexing@sh-48-152:~/Vaccine_work/helloyou$ git reset HEAD helloyou.c
Unstaged changes after reset:
M	helloyou.c

此时查看下状态

wangkexing@sh-48-152:~/Vaccine_work/helloyou$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	modified:   helloyou.c

no changes added to commit (use "git add" and/or "git commit -a")

然后再使用git checkout helloyou.c

wangkexing@sh-48-152:~/Vaccine_work/helloyou$ git checkout helloyou.c
wangkexing@sh-48-152:~/Vaccine_work/helloyou$ git status
On branch master
nothing to commit, working directory clean

猜你喜欢

转载自blog.csdn.net/weixin_43326587/article/details/107620851