git 小记

mkdir workcopy
cd workcopy
git init
git remote add origin /work/git/firstGit.git/
{
git pull origin master
git push origin master
}

vi .git/config

+++[branch "master"]
+++ remote = origin
+++ merge = master

+++ pushurl = /work/git/firstGit.git/
+++ push = refs/heads/master
{
git pull
git push
}

####################################################################
git checkout 切换分支
git add/rm [<.>|<file>] //将文件纳入/移除版本控制
git diff [<.>|<file>] //显示文件改动
git status [-s] //显示文件状态
git show [<version>] //显示提交记录
git blame <file> //显示文件历史修改
git log [<version>] //显示log
git show-ref //显示分支的最后一次commint生成的ID
git reflog //显示最后一次commit生成的ID的前7位
git reset <reflog> //将当前版本回退到reflog版本,reflog号可以在git reflog中查询
git cherry-pick --ff <reflog> //效果类似取消回退,将当前版本还原到reflog版本
git push [<remoteURL> <localBranchName>] //将本地分支提交到远程仓库
git pull [<remoteURL> <localBranchName>] //将远程仓库下载到本地分支
git merge <branch> //将分支branch合并到当前分支
.git/目录下:
HEAD 记录了commint指针的位置,当存在多个分支的时候,HEAD记录了当前使用的是哪个分支ref:refs/heads/branchName 。
refs/heads/branchName 记录了各自分支指针当前位置
logs/HEAD记录所有HEAD指针的变化过程
logs/refs/heads/branchName记录了各自分支指针的变化过程

远程仓库的指针是无法移动的
git init 初始话一个本地仓库
git remote add some_remote ssh://gerrit2@127.0.0.1:29418/test.git 添加一个远程仓库
git fetch some_remote 取出远此仓库索引,
git merge some_remote/master
合并远程仓库内容到本地当前分支
git fetch和git merge合起来相当于git pull

撤销提交
git reset HEAD~1
git merge remote
将远此程仓库合并到当前分支
意即将指针向前回滚1个节点

---------------------------------------------------------------
$ repo init
-u ssh://ip/manifest.git (manifest为清单库,描述了所有协作的库的路径)
-b branchname (下载分支代码)
-m version_name.xml(清单库文件,默认是default.xml,实际上manifest库里面也只有几个xml文件)
--repo-url=ssh://ip/tools/repo.git (下载repo)
--no-repo-verify
--repo-branch=stable

$ Repo sync 同步代码(第一次是直接下载代码,以后是将远程仓库更新取下来合入当前工作分支,封装了git pull?) (repo sync project)
$ Repo start (branchname -all 批量新建)新建分支 (repo abandon)
$ Repo branch 列出分支
$ Repo status 查看状态
$ repo upload 提交到远程(实际是封装了git add,git status,git commit操作)
$ repo forall -p -c <git branch>遍历仓库执行命令

$ git config –-list 查看配置
$ git config --global core.editor vim (加global是全局配置,不加是当前库的配置)
$ git config --global color.ui auto
$ git config --global user.name “xx"
$ git config --global user.email xx@xx.com
$ git config remote.remote_name.push ref/head/*:ref/for/* 配置push路径

$ git checkout –b work-branch-name (在当前分支上新建分支并切换到此分支)
$ git checkout branch-name(切换分支)
$ git checkout filename (重新检出文件,覆盖打当前修改)
$ git checkout commitId file (重新检出commitId处的文件)
$ git branch (列出分支)
$ git branch branch_name ab1afef (在当前分支的comitid为ab1afef的地方创建分支)
$ git branch 查看分支 (git branch –a)
$ git branch –d/D name 删除分支
$ git branch –m old new 重命名分支
$ git branch –merged 查看是否已合并

$ git remote -v (列出远程仓库)
$ git status (查看状态)

$ git diff (当前目录)
$ git diff --cached
$ git diff-tree -p branch (整个分支)

$ git add files (使文件被跟踪或暂存)
$ git stash (存入,在切换到其他分支前可以先执行此命令,再切换回来的时候再git stash stash@{i} 恢复状态)
$ git stash pop (移除最后一次stash)
$ git reflog (列出指针移动轨迹)
$ git show-ref (显示分支的最后一次commintID)
$ git reset (重置跟踪或暂存操作)
$ git reset HEAD@{n} (移动当前分支的HEAD指针到指定节点,相当于放弃部分commit)
$ git push origin local:remote (推送本地local分支到远程origin仓库的remote分支)
$ git log -n -g [--stat] (现在最近N次提交的log)
$ git log --since=2weeks (现在最近2周提交的log)
$ git log --pretty=[oneline short full fuller]
$ git blame <file> (显示文件历史修改)
$ git diff commitId_1 commitId_2 > tmp.diff (将2此提交之间的差异打成patch)
$ git format-patch change (生成补丁邮件)
$ git apply patch-file (将patch合入当前分支)
$ git am patch-file ((移除patch?)

$ git clean –f (清除所有未跟踪的)
$ git rm --cached file (清除缓存中的)

$ git merge branch_name (合并整个branch_name分支到当前分支)
$ git cherry-pick commitid (将commitid合并到当前分支,与git merge branchname类似,但是只合并指定的提交而不是所有)
$ git rebase branch_name (将当前分支合入到branch_name分支,并将合并后的分支作为当前分支)

$ git commit (-s 添加signed-by)提交到本地

$ scp -p -P 29418 username@ip:/hooks/commit-msg ./.git/hooks/ 为commitmsg添加change-id的hook
repo upload 提示public key问题的解决办法
$git config --global review."<reviewip:port>".username <gerrit_username>


附参考文档
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值