Git 版本控制(1) 版本管理

 

Git 用了一年多了 还是基本上那么几个命令 .. .. ..

总结一下 顺便确定一下自己到底会什么。

 


 

 g i t ~

  • 版本控制;
  • 分布式;
  • git 的安装  

 

  git 查看 config 配置信息:

  1.   git config  --system  --list
  2.   git config  --global   --list
  3.   git config  --local     --list

 

    设置 git 默认配置:

  git config --global user.name "Your Name"
  git config --global user.email "email@example.com"

    git config命令的--global参数,用了这个参数,表示你这台机器上所有的Git仓库都会使用这个配置,当然也可以对某个仓库指定不同的用户名和Email地址。

 


 

 

注意文件编码:  设置 , 首选项 , 新建--utf8 with noBom

 

 


 

 

Git 初步:

  1.   cd  ..../.../mytest
  2.   git init       ~ touch a.txt   vi a.txt  .....添加内容
  3.   git  add *
  4.   git commit  -m  "add file a.txt "

  

  1.    git status 
  2.    git diff

      

  1.    git log     /   git  log    --pretty=oneline (版本回退)    /   git   reflog 
  2.    git reset  --hard  d8eb0  HEAD is now at d8eb042 see in gitGui yes

git reflog

可以查看所有分支的所有操作记录(包括已经被删除的 commit 记录和 reset 的操作),

git log

则不能察看已经删除了的commit记录

 

 

 

 工作区暂存区:

  git-repo

  •    add: 将修改文件/改动 添加到暂存区中
  •    commit: 将暂存区提交到当前分支
  •   查看版本库最新版本和工作区中区别:
  •   git diff HEAD -- readme.txt   命令可以查看工作区和版本库里面最新版本的区别

 

 

Git 使用撤销文件:

  •    撤销工作区修改:   git checkout   --  file
  •   撤销暂存区的修改:  git reset HEAD  --  file撤销工作区修改撤销工作区修改 
    • 撤销工作区的修改
      • vi a.txt  add "yes hello hello yes"  
      • git status
      • git checkout  HEAD     /  git checkout -- a.txt    /   git  checkout  a.txt 
    • 撤销暂存区的修改
      • vi a.txt  add "abcdefg"
      • git add *
      • git status
      • git reset HEAD a.txt    / git reset  -- file  / git reset  a.txt  

 

 命令git checkout -- readme.txt意思就是,把readme.txt文件在工作区的修改全部撤销,这里有两种情况:

  • 一种是readme.txt自修改后还没有被放到暂存区,现在,撤销修改就回到和版本库一模一样的状态;
  • 一种是readme.txt已经添加到暂存区后,又作了修改,现在,撤销修改就回到添加到暂存区后的状态。

  

  假设你不但改错了东西,还从暂存区提交到了版本库,可以回退到上一个版本。这是有条件的,就是你还没有把自己的本地版本库推送到远程。Git是分布式版本控制系统.

  

 

Git 删除文件:

  1.   touch  a.txt   ->  git add *  git  commit  -m  "add file a.txt"
  2.     ls  ->    rm  a.txt
  3.   git status   
    1. 撤销删除                      git  checkout  -- a.txt
    2. 从版本库中删除    git  rm  a.txt

 

 

 

 

 

 

 

 

 

 

 

 


 

 

其他:

git如何避免”warning: LF will be replaced by CRLF“提示?
windows平台下使用git add文件时出现”warning: LF will be replaced by CRLF“提示。

在网上很多博客说设置core.autocrlf=false,但是这样不就是把专门给多平台协作配置的功能给废除了吗?
这个问题困扰了我好久,想请教大家:
1、设置core.autocrlf=false时,多人多平台协作开发时会导致哪些问题?windows环境下开发的代码部署到linux生产机上后会导致哪些问题?
2、如果设置core.autocrlf=true才是正确的选择,怎样才能避免add文件时出现“LF will be replaced by CRLF”的提示?


url:
    https://www.zhihu.com/question/50862500?sort=created

 

 

 

posted @ 2017-08-28 12:19  silvercell  阅读(2074)  评论(0)    收藏  举报