sdfouhdso888 发表于 2018-9-17 08:53:16

git 笔记

  git 的使用
  1、配置自己的GIT
  git config --global user.name "You name"
  git config --blobal user.mail "example@example.com"
  查看日志
  git log
  example:
  修改文件file3.txt
  不添加,使用   git diff 查看不同,添加后查看不到
  添加已经修改的文件:
  git add file3.txt
  查看状态
  git status
  提交已经修改的文件:
  git commit --author='wyl wyl@vcmy.com' -m 'add line I'm fine!'
  版本回退:
  先用git log 显示所有日志
  # git log --pretty=oneline
  9ea25f9cf879103de09a7bc377b83cfe5636463e add line fdfdffd
  5ef21d6039755875479ac697a43224de1a89fffe file3
  00581305e6dc9da51bab4595b0b66834cd2743b2 add line heloo today
  962aff30e8e7853c2540dacf0cb1a3cb44eab9be add file3.txt
  d1a0d05724498d991ac2f93934aa1f9024d06580 add 2 files
  d1a11fb72b251783d78e4ad7d937e52cc3b22504 wrote a readme file
  git reset 命令回退版本
  git reset --hard HEAD~5   表示回到第五行的版本,也就是第一个版本,一但回到从前,就到不了未来了。 现在git log 没有了很多日志, 但是有一个办法可以回到最新修改。 就是只要窗口没有关闭,
  找到 9ea25f9cf879103de09a7bc377b83cfe5636463e add line fdfdffd,    git reset --hard 9ea25f9cf879103de09a7bc377b83cfe5636463e   就可以回到未来了。
  git reflog查看每次reset 和提交的记录
  HEAD指向的版本就是当前版本,因此,Git允许我们在版本的历史之间穿梭,使用命令git reset --hard commit_id。
  穿梭前,用git log可以查看提交历史,以便确定要回退到哪个版本。
  git checkout -- readme.txt
  要重返未来,用git reflog查看命令历史,以便确定要回到未来的哪个版本。
  命令git checkout -- readme.txt意思就是,把readme.txt文件在工作区的修改全部撤销,这里有两种情况:
  一种是readme.txt自修改后还没有被放到暂存区,现在,撤销修改就回到和版本库一模一样的状态;
  一种是readme.txt已经添加到暂存区后,又作了修改,现在,撤销修改就回到添加到暂存区后的状态。
  总之,就是让这个文件回到最近一次git commit或git add时的状态。
  现在,看看readme.txt的文件内容:
  现在,假设你不但改错了东西,还从暂存区提交到了版本库,怎么办呢?还记得版本回退一节吗?可以回退到上一个版本。不过,这是有条件的,就是你还没有把自己的本地版本库推送到远程。还记得
  Git是分布式版本控制系统吗?我们后面会讲到远程版本库,一旦你把“stupid boss”提交推送到远程版本库,你就真的惨了……
  git分支
  查看分支:git branch
  创建分支:git branch
  切换分支:git checkout
  创建+切换分支:git checkout -b
  合并某分支到当前分支:git merge
  删除分支:git branch -d
  远程仓库:
  在自己的机器上创建ssh密钥
  $ ssh-keygen -t rsa -C "youremail@example.com"
  在自己的虚拟机上生成密钥ssh-keygen -t rsa -C 'wyl@vcmy.com'

  cat>  chmod 660 authorized_keys
  添加GIT服务器的hosts   vi /etc/hosts    ###添加controller
  添加远程仓库:
  git add origin origin root@controller:/opt/git/sample.git
  git remote rm controller_origin##删除远程仓库
  从公司GIT服务器远程GIT下来
  git clone root@controller:/opt/git/horizon
  做完修改后提交到远程仓库:
  git push wyl_origin master
  下载远程仓库代码:
  git clone root@controller:/opt/git/horizon

页: [1]
查看完整版本: git 笔记