git全局设置:
git config --global user.name "lujiahao"
git config --global user.email "xinruodingshui@gmail.com"
---------------------------------------------------------------------------------------------------------------------------
创建git仓库
mkdir testgit
cd testgit
git init
touch README.md
------------------------------------------------------------------------------------------------------------------------------
添加文件
git add file
git commit -m "the first file to commit" file
git remote add origin https://github.com/xinruodingshui/testgit.git 远程的仓库是空的
git push origin master
把本地master分支的最新修改推送到github上了,现在你就拥有了真正的分布式版本库了。
排除文件:.gitignore
把文件名填进去就行了
git add . 添加当前目录下所有文件
git commit -am "submit bin"
例如:java中的bin文件夹不用版本控制的
git diff
git diff --staged:workspace vs staged 默认命令
git diff --cached:stage vs local repo
git rm
git rm bin1.dll 这个命令执行后实际截图如下:
如果想反悔的话,可以从本地仓库中checkout 命令:git checkout -- bin1.dll
其实这样操作索引区并不是实际上的删除操作
实际上的删除操作
git rm bin1.dll
git status
git commit -a -m "delete bin1.dll"
git status
git checkout -- bin1.dll 这时使用这个命令就找不回bin1.dll了,实际上的删除操作了
移动文件同上
git mv bin.dll 为了是版本仓库生效,要提交的.
git remote 查看与远程仓库的关联
git push origin master origin:远程仓库的别名 master:本地的分支名 这两个分别是远程和本地的默认分支名
分支 merge
git branch lujiahao 建立lujiahao的分支
git checkout lujiahao 切换到lujiahao分支
git show-branch 比较分支间的差异
git diff master lujiahao 比较连个分支之间的差异
合并分支
方法一: git merge “merge branch1 to master" HEAD branch1 HEAD表示当前最新版本
eg: git merge "merge lujiahao to master" HEAD lujiahao
方法二:git checkout master git pull branch1
标签 tag
git tag -a Beta1 -m "make beta1"
修改过后要标记 git tag -a Beta2 -m "make beta2"
切换到beta1版本