阅读:5169回复:1

Git 常用操作命令

楼主#
更多 发布于:2019-06-28 14:46
概要:

git包含一个工作区,也就是你的目录(不包括.git文件夹)
还有一个暂存区stage,git add后,文件暂存在这里
还有一个真正仓库,git commit后,文件改动真正被仓库记录

图片:git.png





git操作全过程:

1.创建仓库
在一个目录下(可以非空目录,也可以空目录),输入命令:
git init
2.查看仓库(工作区)当前状态
git status
3.查看文件修改前后差异
git diff xxx.c
或者查看仓库中的最新版本和工作区的某个文件差异
git diff HEAD -- test.c
4.把文件添加到仓库(暂存区,并非真正的仓库)
git add xxx.c
或者添加所有的文件
git add -A
5.将添加的文件正式提交到真正的仓库
git commit -m "message of commit"
6.查看提交日志
git log
或者用单行模式查看日志
git log --pretty=oneline
或者查看某一个版本的具体修改内容
git show xxxxxxxxx(版本号)
7.版本修改错误有bug,要回退版本
git reset --hard xxxxxxxxx(版本号)
或者回到上n个版本
git reset --hard HEAD~n
取消回退又不确定版本号是多少?用以下命令来查看回退log的版本号,然后在用上面的命令来回退或者取消回退
git reflog
8.恢复工作区的某个文件到最近的一次add或者commit
git checkout -- test.c
恢复暂存区的某个文件,退回到工作区
git reset HEAD test.c
9.从仓库(暂存区)中删除文件
git rm test.c
git commit -m "delete test.c"     //确认删除,同步到真正的仓库
==========================================================================
10.创建并且切换分支
git checkout -b newbranchname
创建分支
git branch newbranchname
切换分支
git checkout branchname
切换分支时,当前分支缓存区中的未提交改动会消失,使用以下命令保存当前现场
git stash
从其他分支处理完后,切回来恢复现场
git stash pop
查看分支
git branch
查看分支合并情况
git log --graph --pretty=oneline --abbrev-commit
合并某分支到当前分支
git merge otherbranchname
删除分支
git branch -d branchname
11.克隆远程分支
git clone git@github.com:jjlin77/git_projectname.git
12.同步到远程分支
git push origin localbranch_name
13.删除远程分支
git push origin :localbranch_name
或者
git push origin --delete localbranch_name
==========================================================================
14.将某一次提交生成patch
git format-patch -1 <r1>             r1为具体的commit提交号
15.打上补丁patch
git apply xxxx.patch               xxxx.patch替换为实际的patch文件
16.设置git自动保存密码:

git config --global user.name "mark.lin"
git config --global user.email "mark.lin@vaststargames.com"
git config --global credential.helper store

最新喜欢:

zhaoyf13zhaoyf...
If you have nothing to lose, then you can do anything.
沙发#
发布于:2019-07-08 19:01
[url]http://190.lsal.cn/195/1329.gif?0728100424873[/url]
游客

返回顶部