git version control
init and commit
- git init (run in the directionary)
- git add fillname
- git commit -m “some explain word”
statecheck
- git status (check the changes happend in the directory)
- git diff (state the differe)
- git log # --pretty=oneline (check the log of the file)
- git reset --hard HEAD^^^^^^ HEAD~100
- git reset --hard 版本号
- git reflog 查看历史命令
third
- git add --> git commit add添加到暂存库,commit提交到版本库。
- git checkout – readme.txt 复原到上一次修改的状态,如果未提交到暂存区,就直接将源文件恢复到版本库的状态;如果尚未提交,已经add,就恢复到add时的暂存库。
- git reset HEAD readme.txt 撤销暂存区的修改,重新放回工作区。HEAD表示最新版本。
- git checkout – test.txt (其实是用版本库里的版本替换工作区的版本,无论工作区是修改还是删除,都可以“一键还原”。)
- git rm 删除文件
fourth
- git remote add origin git@github.com:ArmendLee/publish_pc2.git 添加远程仓库
- git init 之后 首先要 git add . 然后 git commit -m “some words” 然后才可以提交
- git push -u origin master
- git push origin master
git branch
$ git checkout -b dev
Switched to a new branch 'dev'
$ git branch lhd #创建lhdbranch
$ git checkout lhd #切换到lhd
Switched to branch 'dev'
$ git checkout master #切换到masterbranch
Switched to branch 'master'
$ git merge lhd #在master下面运行,将lhd分支合并到当前分支
$ git branch -d lhd #删除分支lhd
$ git branch #查看分支
git branch merge
在git 中,分支合并只需要
git merge feature1
就可以了,在一个分支下合并另一个分支,对于多个分支修改的文件,会出现冲突,这个时候需要手动编辑冲突文件,git会在文件中用不同的箭头来表示,手动编辑后,重新add 和commit。
- 使用
git log --graph --pretty=oneline --abbrev-commit
来查看分支的合并情况。 - 在merge的时候加上一行参数 --no-ff 禁用fast forward,会让merge操作类似于commit操作,即使删除分支后,依然可以看到merge信息。但是,commit操作必须加上 -m “描述字符” 的参数,因此,需要像下面这样
git merge --no-ff -m "merge with no-ff" dev