git中的指令

来源:互联网 发布:cutecom串口发送数据 编辑:程序博客网 时间:2024/06/05 15:11

git中的指令

本文借鉴自颜海镜的博客-我的git笔记
如有侵权,定将删除。

配置

配置账号信息

git config -e [--global] #编辑Git配置文件git config --global user.name ReedSungit config --global user.email sunhongzhao@foxmail.comgit config --list #查看配置的信息git help config #获取帮助信息

配置自动换行

git config --global core.autocrlf input #提交到git使自动换行符转换为lf

配置密钥

ssh0keygen -t rsa -C sunhongzhao@foxmail.com #生成密钥ssh -T git@github.com #测试是否成功

配置别名

git config --global alias.st status #git stgit config --global alias.co checkout #git cogit config --global alias.br branch #git brgit config --global alias.ci commit #git ci

新建仓库

git init #初始化git status #获取状态git add [file1] [file2] ... #或*代表全部添加git commit -m "message" #提交git remote add origin git#github.com:ReedSun/***git  #添加源git push -u origin master #push同时默认跟踪分支

从现用仓库克隆

git clone git://github.com/ReedSun/***git

本地

git add * # 跟踪新文件git add -u [path] # 添加[指定路径下]已跟踪文件rm *&git rm * # 移除文件git rm -f * # 移除文件git rm --cached * # 停止追踪指定文件,但该文件会保留在工作区git mv file_from file_to # 重命名跟踪文件git log # 查看提交记录git commit # 提交更新   git commit [file1] [file2] ... # 提交指定文件 git commit -m 'message'git commit -a # 跳过使用暂存区域,把所有已经跟踪过的文件暂存起来一并提交git commit --amend#修改最后一次提交git commit -v # 提交时显示所有diff信息git reset HEAD *#取消已经暂存的文件git reset --mixed HEAD *#同上git reset --soft HEAD *#重置到指定状态,不会修改索引区和工作树git reset --hard HEAD *#重置到指定状态,会修改索引区和工作树git reset -- files#重置index区文件git revert HEAD #撤销前一次操作git revert HEAD~ #撤销前前一次操作git revert commit ## 撤销指定操作git checkout -- file#取消对文件的修改(从暂存区——覆盖worktree file)git checkout branch|tag|commit -- file_name#从仓库取出file覆盖当前分支git checkout -- .#从暂存区取出文件覆盖工作区git diff file #查看指定文件的差异git diff --stat #查看简单的diff结果git diff #比较Worktree和Index之间的差异git diff --cached #比较Index和HEAD之间的差异git diff HEAD #比较Worktree和HEAD之间的差异git diff branch #比较Worktree和branch之间的差异git diff branch1 branch2 #比较两次分支之间的差异git diff commit commit #比较两次提交之间的差异git log #查看最近的提交日志git log --pretty=oneline #单行显示提交日志git log --graph # 图形化显示git log --abbrev-commit # 显示log id的缩写git log -num #显示第几条log(倒数)git log --stat # 显示commit历史,以及每次commit发生变更的文件git log --follow [file] # 显示某个文件的版本历史,包括文件改名git log -p [file] # 显示指定文件相关的每一次diffgit stash #将工作区现场(已跟踪文件)储藏起来,等以后恢复后继续工作。git stash list #查看保存的工作现场git stash apply #恢复工作现场git stash drop #删除stash内容git stash pop #恢复的同时直接删除stash内容git stash apply stash@{0} #恢复指定的工作现场,当你保存了不只一份工作现场时。

分支

git branch#列出本地分支git branch -r#列出远端分支git branch -a#列出所有分支git branch -v#查看各个分支最后一个提交对象的信息git branch --merge#查看已经合并到当前分支的分支git branch --no-merge#查看为合并到当前分支的分支git branch test#新建test分支git branch branch [branch|commit|tag] # 从指定位置出新建分支git branch --track branch remote-branch # 新建一个分支,与指定的远程分支建立追踪关系git branch -m old new #重命名分支git branch -d test#删除test分支git branch -D test#强制删除test分支git branch --set-upstream dev origin/dev #将本地dev分支与远程dev分支之间建立链接git checkout test#切换到test分支git checkout -b test#新建+切换到test分支git checkout -b test dev#基于dev新建test分支,并切换git merge test#将test分支合并到当前分支git merge --squash test ## 合并压缩,将test上的commit压缩为一条git cherry-pick commit #拣选合并,将commit合并到当前分支git cherry-pick -n commit #拣选多个提交,合并完后可以继续拣选下一个提交git rebase master#将master分之上超前的提交,变基到当前分支git rebase --onto master 169a6 #限制回滚范围,rebase当前分支从169a6以后的提交git rebase --interactive #交互模式  git rebase --continue# 处理完冲突继续合并    git rebase --skip# 跳过   git rebase --abort# 取消合并

远端

git fetch origin remotebranch[:localbranch]# 从远端拉去分支[到本地指定分支]git merge origin/branch#合并远端上指定分支git pull origin remotebranch:localbranch# 拉去远端分支到本地分支git push origin branch#将当前分支,推送到远端上指定分支git push origin localbranch:remotebranch#推送本地指定分支,到远端上指定分支git push origin :remotebranch # 删除远端指定分支git push origin remotebranch --delete # 删除远程分支git branch -dr branch # 删除本地和远程分支git checkout -b [--track] test origin/dev#基于远端dev分支,新建本地test分支[同时设置跟踪]

git remote add origin1 git@github.com:yanhaijing/data.js.gitgit remote#显示全部源git remote -v#显示全部源+详细信息git remote rename origin1 origin2#重命名git remote rm origin#删除git remote show origin#查看指定源的全部信息

标签

git tag#列出现有标签  git tag v0.1 [branch|commit] # [从指定位置]新建标签git tag -a v0.1 -m 'my version 1.4'#新建带注释标签git checkout tagname#切换到标签git push origin v1.5#推送分支到源上git push origin --tags#一次性推送所有分支git tag -d v0.1#删除标签git push origin :refs/tags/v0.1#删除远程标签

参考资料

我的git笔记-颜海镜的博客

0 0
原创粉丝点击