git的学习笔记

来源:互联网 发布:最燃的一句话 知乎 编辑:程序博客网 时间:2024/05/22 10:21
git 学习指南:
http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/001373962845513aefd77a99f4145f0a2c7a7ca057e7570000


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 <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." 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 <file>..." 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 <name>

切换分支:git checkout <name>

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

合并某分支到当前分支:git merge <name>

删除分支:git branch -d <name>
0 0
原创粉丝点击