您的位置:首页 > 其它

git 积累

2014-04-30 15:46 288 查看
1、git  log 的用法,具体参考 git log --help,以下是个人在使用中遇见的问题,略作统计。

查看单个文件的修改差异(类似于查看单个文件的log,同时将每次log 的详细记录都显示出来):

        git log --full-diff

Without this flag, git log -p <path>...shows commits that touch the specified paths, and diffs about the same specified paths.
With this, the full diff is shown for commits that touch the specified paths; this means that "<path>…" limits only commits, and doesn’t limit diff for those commits.

清晰,精简的log可以使用:

git log --abbrev-commit --pretty=oneline

$ git log -p  <path>... test.c
$ git log -u  <path>... test.c
$ git log -patch  <path>... test.c


具体查看,结合使用 -p --stat 效果更清晰,详细参考git-log help的COMMAN DEFF OPTIONS:
$ git log -p --stat <path>...test.c


2、git pull 或 git commit 出现如下错误,是因为文件夹权限被修改
error: insufficient permission for adding an object to repository database .git/objects

只需修改下权限即可解决  sodu chrom 777 .git/objects/  -R

3、git  remote 远程服务器路径修改

如果(服务器)地址或者路径更换,需重新链接到远程服务器上,必须重新设置远程服务器地址。

git remote -v  //查看远程仓库地址
git remote set-url origin (new_remote_git_address)  //迁移到新仓库地址


new_remote_git_address : 新的远程仓库地址

4、git branch 分支操作

设置XXX分支为远程默认分支:git branch --set-upstream-to=origin/XXX

git branch 查看本地分支
* dev (*当前位于dev分支)
master
git branch --remote 查看远程分支
origin/dev
origin/master
git checkout -b <new_branch> 创建分支
git checkout <another_branch> 切换分支
git push origin <branch_name> push本地分支代码到远端服务器,如果没有该分支,自动创建
git pull origin <branch_name> pull远端分支代码到本地对应分支
git checkout b_branch 删除本地分支,首先切换到别的分支,然后才能删除
git branch -d a_branch
git push origin --delete branch_name 删除远程分支
git merge b 合并本地分支,假设当前分支为a,将本地的b分支代码合并到a中
git merge origin/b 合并远程分支,和前面的几乎一样


5、git bash 快速复制粘贴

在Bash命令界面,鼠标右击Bash边框上沿,Properties->Options->Edit Options->QuickEdit Mode 前面打上勾,就OK了。

Bash界面的快速复制粘贴默认是关闭了的,为什么,我也不知道!

6、错误:
$ git diff util/webkit/mkdist-webkit
diff --git a/util/webkit/mkdist-webkit b/util/webkit/mkdist-webkit
old mode 100755
new mode 100644
解决:
git config --global core.filemode false
git config core.filemode false
原因:权限问题

7、git cherry

如果你想确认本地commit的代码是否push到服务器上时,可用

git cherry -v   //显示本地commits但是未push的提交


8、git status

查看分支详细状态,同时会显示本地commits,但是未push到服务器上的代码。

9、 git clone -b <xx_branch> aaa.git

只clone xx_branch到本地,不clone其他分支,节约资源和分支。

10、git add

a)增加修改过文件到缓存区,commit前执行;commit 的时候不建议使用 -a

b)个人新增文件,提交前一定要先add

11、git clean 

清除未跟踪文件

git log 的用法很多,慢慢累积,也在此慢慢记录。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息