学习笔记(楚才国科)

git学习指南
http://backlogtool.com/git-guide/cn/

git的基本命令:
把一个文件放到Git仓库只需要两步:
1.git add file
2.git commit -m “explain”

查看当前仓库的状态:
git status
分三种情况
1.仓库文件没有改动,没有变化
$ git status

On branch master

nothing to commit, working directory clean

2.仓库文件有变动,1.例如你修改了文件的内容,需要commit 2.你添加的新的文件需要commit

On branch master

Changes not staged for commit:

(use “git add …” to update what will be committed)

(use “git checkout – …” to discard changes in working

#

modified: s.txt

#
no changes added to commit (use “git add” and/or “git commit -a”)

很明显修改了s.txt的内容。

On branch master

Untracked files:

(use “git add …” to include in what will be committed)

#

status.txt

nothing added to commit but untracked files present (use “git add” to track)
没有跟踪的文件,status.txt是先添加的文件

对比文件修改和修改之前的差异内容
git diff file

版本回退(注释很重要)
1.查看所有版本信息
git log

2.回退到上一个版本
上一个版本就是HEAD^,上上一个版本就是HEAD^^,当然往上100个版本写100个^比较容易数不过来,所以写成HEAD~100
git reset –hard HEAD^
git reset –hard 版本号

撤销修改
当你改乱了工作区某个文件的内容,想直接丢弃工作区的修改时,用命令git checkout – file
当你不但改乱了工作区某个文件的内容,还添加到了暂存区时,想丢弃修改,分两步,第一步用命令git reset HEAD file,就回到了场景1,第二步按场景1操作。

删除一个文件
git rm file 用于删除一个文件

合并分支:
查看分支:git branch

创建分支:git branch

切换分支:git checkout

创建+切换分支:git checkout -b

合并某分支到当前分支:git merge

删除分支:git branch -d

猜你喜欢

转载自blog.csdn.net/weixin_43092451/article/details/82688726
今日推荐