git的使用方式

来源:互联网 发布:木头马尾原创服装淘宝 编辑:程序博客网 时间:2024/04/30 18:37

GIT的使用方式:

git config --global user.name "xxxxxx" #用户名  git config --global user.email "12345678@qq.com" #邮箱  git config --global core.editor vim #编辑器  git config --global alias.st status #按这种方法,配置别名    文件的比较  git diff <file> 比较工作区于暂存区文件的差异  git diff --cached 比较暂存区和版本库的区别  git diff <$id1> <$id2> 比较两次提交之间的差异  git diff <branch1>..<branch2> 在两个分支之间比较分支    分支  git branch -r 查看远程分支  git branch new_branch_name 新建一个分支  git branch --merged 查看已经被合并到当前分支的分支  git branch --no-merged 查看未被合并到当前分支的分支  git checkout branch_name 切换分支  git checkout -b branch_name 切换分支并创建  git branch -d branch_name 删除分支  git branch -D branch_name 强制删除分支  git pull origin not_master_branch 将远程的not_master_branch分支pull下来  git push origin not_master_branch 将修改的not_master_branch分支push到master    远程  git remote -v 查看远程服务器地址和仓库名称  git remote show origin 查看远程服务器仓库状态  git remote add origin git@123445. 添加远程仓库地址git remote set-url origin git@github.com 修改远程地址git remote rm 删除远程仓库地址从远程拉取内容,提交内容到远程git pull = git fetch + git mergegit fetch 拉取git merge 合并git push push所有分支git push origin master 将本地主分支推到远程主分支git push -u origin master 将本地主分支推到远程(如没有远程主分支则创建,用于 初始化远程仓库)<git push origin <local_branch> 创建远程分支,origin是远程仓库名git push origin<local_branch>:<remote_branch> 创建远程分支git push origin :<remote_branch> 先删除本地分支(git br -d <branch>),然后在push删除远程分支暂存管理 git stash 将工作区做的修改暂存到一个git栈中 git stash list 查看栈中所有暂存git stash clear 清空暂存栈   创建远程库  git clone --bare git_url_path clone的时候,将其创建成远程仓库git --bare init 初始化项目的时候,创建成远程仓库   列出所有tag新建一个tag在当前commitgit tag [tag]新建一个tag在指定commit git tag [tag] [commit]查看tag信息  git show [tag]提交指定taggit push [remote] [tag]提交所有taggit push [remote] --tags 新建一个分支,指向某个tag  git checkout -b [branch] [tag]显示有变更的文件 git status  显示当前分支的版本历史git log  显示commit历史,以及每次commit发生变更的文件  git log --stat显示某个文件的版本历史,包括文件改名git log --follow [file]git whatchanged [file] 显示指定文件相关的每一次diffgit log -p [file]  显示指定文件是什么人在什么时间修改过git blame [file] 显示暂存区和工作区的差异git diff显示暂存区和上一个commit的差异git diff --cached [file]  显示工作区与当前分支最新commit之间的差异  git diff HEAD  显示两次提交之间的差异  git diff [first-branch]...[second-branch] 显示某次提交的元数据和内容变化git show [commit]  显示某次提交发生变化的文件git show --name-only [commit]  显示某次提交时,某个文件的内容git show [commit]显示当前分支的最近几次提交  git reflog 下载远程仓库的所有变动git fetch [remote]显示所有远程仓库  git remote -v显示某个远程仓库的信息git remote show [remote]增加一个新的远程仓库,并命名git remote add [shortname] [url]取回远程仓库的变化,并与本地分支合并git pull [remote] [branch] 上传本地指定分支到远程仓库git push [remote] [branch] 强行推送当前分支到远程仓库,即使有冲突git push [remote] --force推送所有分支到远程仓库git push [remote] --all  恢复暂存区的指定文件到工作区git checkout [file]恢复某个commit的指定文件到工作区git checkout [commit] [file]恢复上一个commit的所有文件到工作区git checkout .重置暂存区的指定文件,与上一次commit保持一致,但工作区不变git reset [file] 重置暂存区与工作区,与上一次commit保持一致  git reset --hard 重置当前分支的指针为指定commit,同时重置暂存区,但工作区不变git reset [commit] 重置当前分支的HEAD为指定commit,同时重置暂存区和工作区,与指定commit一致>  git reset --hard [commit]重置当前HEAD为指定commit,但保持暂存区和工作区不变git reset --keep [commit] 新建一个commit,用来撤销指定commit# 后者的所有变化都将被前者抵消,并且应用到当前分支git revert  

寻找谁是始作俑者

寻找谁更改了一个文件中的一行代码经常会用到。

    git blame FILE

有时更改自于前一个文件(如果你已经合并了两个文件,或者你已经移动了一个函数),因此你可以这样使用

    git blame -C FILE

有时通过向前或向后点击来进行变化跟踪,这是很好的方法。有一个内置的 GUI 程序专门为此设计:

    git gui blame FILE

数据库的维护

Git 通常不需要大量维护,它基本上可以自我维护。然而,你可以使用如下命令查看数据库统计信息:

    git count-objects -v

如果数值很高,你可以选择使用垃圾回收你的重复内容。这不会影响推送或者其它用户,但却可以让你的命令运行更快且占用更少空间:

    git gc

经常运行一致性检查也是值得推荐的做法:

    git fsck -- full




git的详细使用方法




0 0
原创粉丝点击