//-----------用法部分------------------------------------------------------
有用的git用法网址:
1. http://www.worldhello.net/gotgithub/03-project-hosting/020-repo-operation.html 中文
2. http://schacon.github.com/git/git-push.html#OPTIONS
3. http://progit.org/book/zh/ 中文
4. http://gitref.org/remotes/
5. http://gitbook.liuhui998.com/3_6.html 中文
6. http://git-scm.com/book/en/Git-Tools-Submodules
7. http://github.danmarner.com/section/ch6-6/ 中文 貌似翻译的6
//-----------问题部分------------------------------------------------------
1. 新建git库
git --bare init 或 git init
当提交修改并PUSH出错时:
修改 .git/config 添加
[receive]
denyCurrentBranch = ignore
原因:
默认未开通写权限
2. 将本地新分支推送到远程创建新分支时出错解决办法:
场景:
git co -b new1
git add *
gitt ci -m ...
当git push origin new1
尝试将本地新建分支推送到远程创建新分支时出错:
$ git push origin sql
error: src refspec sql does not match any.
error: failed to push some refs to '../git4s.git'
尝试:
git push -u origin sgl
说明:
-u, --set-upstream
For every branch that is up to date or successfully pushed, add
upstream (tracking) reference, used by argument-less git-pull(1)
and other commands. For more information, see branch.<name>.merge
in git-config(1).
========= git merge =============
可以merge.
1. merge分支。
如果当前是branch1,想将master的所有内容合并到branch1。则
git merge master.
2. 提交一个patch.
----1. 合并某一个已推送的历史提交,而且将之前提交的所有信息都重新提交到这里。(相当于merge一个diff进来)
首先切换在你想diff的源分支,运行
git format-patch -C -M commit1..commit2
会生成文件0001-somethin.patch
然后回来你的目的分支,运行
git am 0001-something.patch
如果失败,则
git applay 0001-something.patch --reject (--reject意思是说如果有冲突不中止,保留冲突并继续,将冲突文件生成一个.rej的文件)
然后手动修复冲突,再运行
git add a/b/c/...
git am --resolved.
这时会看到本地已有已经的提交,且那些提交信息都已保留。
最后git push.
-----2. 自己生成一个patch
运行git diff > a.patch
然后到目前的分支上,git apply a.patch
git push.
===============================
如果某个branch br1有提交 abcdef,
想把提交完全重新提交到master ,则到master 下,
git cherry-pick abcdef
git push.
如果有冲突,手动解决再commit.
======================
git 找回丢失的匿名分支的提交记录
如果有匿名分支的提交,然后又切换到其它分支,这里刚才的无名分支就会再也回不来,因此也找不到那个分支的commit。
找回办法:
git reflog
会返回一系统commit,
找到自己的commit: abede,
然后git branch lost abcde.
会得到包含那个提交的新分支。
==========================