git
git: 输入git可以看看系统有没有安装git
yum install git 创建版本库
git init :初始化一个Git仓库
[root@localhost ~]# mkdir learngit [root@localhost ~]# cd learngit [root@localhost learngit]# pwd /root/learngit [root@localhost learngit]# git init Initialized empty Git repository in /root/learngit/.git/
多了一个.git的目录,是用来跟踪管理版本库的
把文件添加到管理库:
第一步:
git add +文件名 :把文件添加到仓库暂存区 一定要放在git可以管理的目录下
[root@localhost learngit]# vi readme.txt [root@localhost learngit]# rmdir readme.txt [root@localhost learngit]# pwd /root/learngit [root@localhost learngit]# vi readme.txt [root@localhost learngit]# git add readme.txt
第二步:
git commit -m “版本说明” :把文件提交到仓库
[root@localhost learngit]# git commit -m "first edition" [master (root-commit) c04c4d2] first edition Committer: root <root@localhost.localdomain> Your name and email address were configured automatically based on your username and hostname. Please check that they are accurate. You can suppress this message by setting them explicitly: git config --global user.name "Your Name" git config --global user.email you@example.com After doing this, you may fix the identity used for this commit with: git commit --amend --reset-author 1 file changed, 4 insertions(+) //一个文件被改动,插入了两行内容 create mode 100644 readme.txt
git status 掌握仓库目前状态
git diff 工作区与暂存区的差异 文件被修改,查看修改了什么内容
git diff HEAD -- readme.txt查看工作区和库的差异
git diff --cached 暂存区与库的差异
-
要随时掌握工作区的状态,使用
git status命令。 -
如果
git status告诉你有文件被修改过,用git diff可以查看修改内容。
然后再 git add 然后再git status看状态 然后再git commit 然后git status
git log 查看历史版本 最近到最远
git log --pretty=oneline 查看简略版本信息
get reset --hard HEAD^退回到上一个版本
git reset --hard [ID]:想回到未来某个版本 可以顺着网上找append GPL的commit id
git reflog 记录每一次命令(从前往后查看历史命令)
git checkout -- readme.txt (撤销到进入add之前 ) 把文件在工作区的修改全部撤销
git reset HEAD readme.txt (撤销到进入commit之前)
git reset --hard HEAD^ 已经提交到库使用版本回退
删除文件 :git status 看目前工作状态 git rm test.txt 删除该文件 git commit 提交到仓库
生成公钥私钥 :ssh-keygen -t rsa -C "youremail@example.com"
如果一切顺利的话,可以在用户主目录里找到.ssh目录,里面有id_rsa和id_rsa.pub两个文件,这两个就是SSH Key的秘钥对,id_rsa是私钥,不能泄露出去,id_rsa.pub是公钥,可以放心地告诉任何人
绑定远程库(需改成自己的账号链接)
git remote add origin git@github.com:michaelliao/learngit.git
把本地master分支推送到远程仓库(首次推送加-u)
git push -u origin master
创建分支 dna,切换到dna分支:it checkout -b dna
[root@localhost learngit]# git checkout -b dna Switched to a new branch 'dna'
git checkout -b dna等价于:
git branch dna 创建分支
git checkout dna git switch dna切换分支
查看当前分支 :git branch (会列出所有分支,当前分支带*)
合并某分支到当前分支:git merge <name>
删除分支:git branch -d <name>
把工作区的工作场景暂时保存:git stash
查看保存的工作场景:git stash list
恢复工作区场景但是不删除对工作区场景的存储:git stash apply
恢复并删除工作区场景:git stash pop
强制删除一个没有合并过的分支:git branch -D <name>

浙公网安备 33010602011771号