Git学习笔记

文件的三种状态

  • Committed means that the data is safely stored in your local database.
  • Modified means that you have changed the file but have not committed it to your database yet.
  • Staged means that you have marked a modified file in its current version to go into your next commit snapshot.

文件结构

image_1c4he4u4m1usq12bi1hl11irb9od9.png-46.8kB

工作流

  1. You modify files in your working tree.
  2. You selectively stage just those changes you want to be part of your next commit, which adds only those changes to the staging area.
  3. You do a commit, which takes the files as they are in the staging area and stores that snapshot permanently to your Git directory.

设置

$ git config

git管理下目录中文件的类型

  1. Tracked 文件是git追踪的文件,每次快照中的文件。
  2. Untracked 文件是其他git不追踪的文件,每次快照不涉及。
    image_1c4hhfaa0n3e1vth18v8qjmbucm.png-34.6kB

基本操作

  • 添加一个项目到git repository
<用cd跳转到项目目录下>
$ git init
//这时项目下的文件还没有建立index
  • 获得一份repository的克隆
$ git clone <url>
  • 查看git目录下的文件状态,默认只有tracked文件
$ git status    //详细状态
$ git status -s //简写状态
  • stage一个文件
    即所以把红字状态变成绿字状态的操作
$ git add <file name>
  • 将文件回退到最近的committe
$ git checkout -- <file>
//危险指令,所以改动将不会被保存
  • commit到仓库(只有绿字状态(Modified,new file)状态才可以commit)
$ git commit -m "Some notation here"
//每次commit需要写明做了什么
$ git commit --amend//commit到最近的一个版本,即补交
  • 版本历史
$ git log
$ git log --pretty=oneline //简洁log
//--since,--until 限制时间
  • 查询当前有哪些文件做了改动
git diff
  • 版本回退
$ git reset --hard <版本号>
  • 查看命令记录
$ git reflog
  • unstaging a staged file
$ git reset HEAD <file>
  • 查看远程repository
$ git remote -v
  • 添加一个远程repository
$ git remote add <shortname> <url>
  • 查看远程repository的状态
$ git fetch <remote>
  • 保存到远程repository中
$ git push <remote> <branch>
  • 查看远程repository的文件状态
$ git remote show <remote>
  • 对远程repository重命名
$ git remote rename pb paul
  • 显示tag
$ git tag
  • 添加tag
$ git tag -a <tagname> -m "<annotation>"
  • 显示某tag的相关信息
$ git show <tagname>
posted @ 2018-01-24 10:25  我也想学编程  阅读(125)  评论(0编辑  收藏  举报