@22221cjp
2016-08-17T15:26:59.000000Z
字数 14162
阅读 1526
工作
默认git clone是clone的 master分支
如果要clone指定分支:
git checkout --track -b [local-branch-name] origin/[origin-branch-name]
git push origin HEAD:chenjp
git commit -a -m ‘test2'
cd /Users/chenjp/Documents/dianping/biz/\.idea/artifactsLast login: Thu May 7 16:17:30 on ttys001chenjp@chenjpdeMacBook-Pro ~$ cd /Users/chenjp/Documents/dianping/biz/\.idea/artifactschenjp@chenjpdeMacBook-Pro artifacts$ pwd/Users/chenjp/Documents/dianping/biz/.idea/artifactschenjp@chenjpdeMacBook-Pro artifacts$ cd ..chenjp@chenjpdeMacBook-Pro .idea$ cd ..chenjp@chenjpdeMacBook-Pro biz$ lsREADME.md beauty-biz-impl biz-parent.iml targetbeauty-biz-api beauty-biz-service pom.xmlchenjp@chenjpdeMacBook-Pro biz$ ls -a. .gitignore beauty-biz-api biz-parent.iml.. .idea beauty-biz-impl pom.xml.git README.md beauty-biz-service targetchenjp@chenjpdeMacBook-Pro biz$ cat .gitignore/.settings/target/test-output/.classpath/.project*.iml**.DS_Storechenjp@chenjpdeMacBook-Pro biz$ echo "/.idea" >> .gitignorechenjp@chenjpdeMacBook-Pro biz$ cat .gitignore/.settings/target/test-output/.classpath/.project*.iml**.DS_Store/.ideachenjp@chenjpdeMacBook-Pro biz$ pqs-bash: pqs: command not foundchenjp@chenjpdeMacBook-Pro biz$ pwd/Users/chenjp/Documents/dianping/bizchenjp@chenjpdeMacBook-Pro biz$chenjp@chenjpdeMacBook-Pro biz$chenjp@chenjpdeMacBook-Pro biz$ lsREADME.md beauty-biz-impl biz-parent.iml targetbeauty-biz-api beauty-biz-service pom.xmlchenjp@chenjpdeMacBook-Pro biz$ cd ..chenjp@chenjpdeMacBook-Pro dianping$ lsbiz promotion-biz-server technician-mobile-webdata promotion-mobile-webiml technician-bizchenjp@chenjpdeMacBook-Pro dianping$ cd technician-biz/chenjp@chenjpdeMacBook-Pro technician-biz$ lsREADME.md technician-biz-api technician-biz-servicepom.xml technician-biz-impltarget technician-biz-parent.imlchenjp@chenjpdeMacBook-Pro technician-biz$ git branch* masterchenjp@chenjpdeMacBook-Pro technician-biz$ pwd/Users/chenjp/Documents/dianping/technician-bizchenjp@chenjpdeMacBook-Pro technician-biz$chenjp@chenjpdeMacBook-Pro technician-biz$ cd ..chenjp@chenjpdeMacBook-Pro dianping$ lsbiz promotion-biz-server technician-mobile-webdata promotion-mobile-webiml technician-bizchenjp@chenjpdeMacBook-Pro dianping$ mkdir technician-biz-masterchenjp@chenjpdeMacBook-Pro dianping$ cd technician-biz-master/chenjp@chenjpdeMacBook-Pro technician-biz-master$ lschenjp@chenjpdeMacBook-Pro technician-biz-master$ pwd/Users/chenjp/Documents/dianping/technician-biz-master//这里突然有的,是因为用工具生成clone了chenjp@chenjpdeMacBook-Pro technician-biz-master$ lsREADME.md technician-biz-api technician-biz-servicepom.xml technician-biz-implchenjp@chenjpdeMacBook-Pro technician-biz-master$ git branch* masterchenjp@chenjpdeMacBook-Pro technician-biz-master$chenjp@chenjpdeMacBook-Pro technician-biz-master$chenjp@chenjpdeMacBook-Pro technician-biz-master$ lsREADME.md technician-biz-api technician-biz-servicepom.xml technician-biz-implchenjp@chenjpdeMacBook-Pro technician-biz-master$ git branch* masterchenjp@chenjpdeMacBook-Pro technician-biz-master$ pwd/Users/chenjp/Documents/dianping/technician-biz-masterchenjp@chenjpdeMacBook-Pro technician-biz-master$chenjp@chenjpdeMacBook-Pro technician-biz-master$chenjp@chenjpdeMacBook-Pro technician-biz-master$ git branch -a* masterremotes/origin/HEAD -> origin/masterremotes/origin/chenjpremotes/origin/hao.yuanremotes/origin/lightmergeremotes/origin/masterchenjp@chenjpdeMacBook-Pro technician-biz-master$ git checkout --track -b chenjp origin/chenjpBranch chenjp set up to track remote branch chenjp from origin.Switched to a new branch 'chenjp'chenjp@chenjpdeMacBook-Pro technician-biz-master$ git branch* chenjpmasterchenjp@chenjpdeMacBook-Pro technician-biz-master$ git checkout masterSwitched to branch 'master'Your branch is up-to-date with 'origin/master'.chenjp@chenjpdeMacBook-Pro technician-biz-master$ git pullAlready up-to-date.chenjp@chenjpdeMacBook-Pro technician-biz-master$ git checkout chenjpSwitched to branch 'chenjp'Your branch is up-to-date with 'origin/chenjp'.chenjp@chenjpdeMacBook-Pro technician-biz-master$ git branch* chenjpmasterchenjp@chenjpdeMacBook-Pro technician-biz-master$ git rebase masterFirst, rewinding head to replay your work on top of it...Applying: 丽人周报提交Using index info to reconstruct a base tree...M technician-biz-service/src/main/resources/config/spring/local/applicationContext-pigeon.xml<stdin>:3362: trailing whitespace.* 根据传入的时间获得当前时间所在周的第一天和第七天日期<stdin>:3363: trailing whitespace.* @param tm 时间<stdin>:3364: trailing whitespace.* @param firstday 周日作为周一为0,周一作为周一1。<stdin>:3513: trailing whitespace.Id, TechnicianId, Name, ShopId, CityId, CategoryId, Star, TotalStar, PopularityRankChange,<stdin>:3514: trailing whitespace.StarRank, StarRankChange, TotalTechnician, BookOrderCount, WeeklyVisits, IsDeleted,warning: squelched 18 whitespace errorswarning: 23 lines add whitespace errors.Falling back to patching base and 3-way merge...Auto-merging technician-biz-service/src/main/resources/config/spring/local/applicationContext-pigeon.xmlCONFLICT (content): Merge conflict in technician-biz-service/src/main/resources/config/spring/local/applicationContext-pigeon.xmlFailed to merge in the changes.Patch failed at 0001 丽人周报提交The copy of the patch that failed is found in:/Users/chenjp/Documents/dianping/technician-biz-master/.git/rebase-apply/patchWhen you have resolved this problem, run "git rebase --continue".If you prefer to skip this patch, run "git rebase --skip" instead.To check out the original branch and stop rebasing, run "git rebase --abort".chenjp@chenjpdeMacBook-Pro technician-biz-master$ lsREADME.md technician-biz-api technician-biz-servicepom.xml technician-biz-implchenjp@chenjpdeMacBook-Pro technician-biz-master$ git branch* (no branch, rebasing chenjp)chenjpmasterchenjp@chenjpdeMacBook-Pro technician-biz-master$ cd technician-biz-service/chenjp@chenjpdeMacBook-Pro technician-biz-service$ lspom.xml srcchenjp@chenjpdeMacBook-Pro technician-biz-service$ cd src/main/chenjp@chenjpdeMacBook-Pro main$ lsjava resources webappchenjp@chenjpdeMacBook-Pro main$ cd resources/chenjp@chenjpdeMacBook-Pro resources$ lsMETA-INF config log4j.xml logback.xmlchenjp@chenjpdeMacBook-Pro resources$ cd config/chenjp@chenjpdeMacBook-Pro config$ lsapplicationContext.properties springchenjp@chenjpdeMacBook-Pro config$ cd spring/chenjp@chenjpdeMacBook-Pro spring$ lslocalchenjp@chenjpdeMacBook-Pro spring$ cd local/chenjp@chenjpdeMacBook-Pro local$ lsapplicationContext-client.xmlapplicationContext-core.xmlapplicationContext-pigeon.xmlapplicationContext-swallow-technicianReview.xmlchenjp@chenjpdeMacBook-Pro local$ ls -a...applicationContext-client.xmlapplicationContext-core.xmlapplicationContext-pigeon.xmlapplicationContext-swallow-technicianReview.xmlchenjp@chenjpdeMacBook-Pro local$ vim applicationContext-pigeon.xmlchenjp@chenjpdeMacBook-Pro local$ cd ..chenjp@chenjpdeMacBook-Pro spring$ lslocalchenjp@chenjpdeMacBook-Pro spring$ cd ..chenjp@chenjpdeMacBook-Pro config$ cd ..chenjp@chenjpdeMacBook-Pro resources$ lsMETA-INF config log4j.xml logback.xmlchenjp@chenjpdeMacBook-Pro resources$ cd ..chenjp@chenjpdeMacBook-Pro main$ cd ..chenjp@chenjpdeMacBook-Pro src$ cd ..chenjp@chenjpdeMacBook-Pro technician-biz-service$ git branch* (no branch, rebasing chenjp)chenjpmasterchenjp@chenjpdeMacBook-Pro technician-biz-service$ git add .chenjp@chenjpdeMacBook-Pro technician-biz-service$ git rebase --continueApplying: 丽人周报提交Applying: update 技师周报chenjp@chenjpdeMacBook-Pro technician-biz-service$ git statusOn branch chenjpYour branch and 'origin/chenjp' have diverged,and have 8 and 2 different commits each, respectively.(use "git pull" to merge the remote branch into yours)nothing to commit, working directory cleanchenjp@chenjpdeMacBook-Pro technician-biz-service$ git rebase masterCurrent branch chenjp is up to date.chenjp@chenjpdeMacBook-Pro technician-biz-service$ git branch* chenjpmasterchenjp@chenjpdeMacBook-Pro technician-biz-service$ git push origin HEAD:chenjpTo git@code.dianpingoa.com:technician/technician-biz.git! [rejected] HEAD -> chenjp (non-fast-forward)error: failed to push some refs to 'git@code.dianpingoa.com:technician/technician-biz.git'hint: Updates were rejected because the tip of your current branch is behindhint: its remote counterpart. Integrate the remote changes (e.g.hint: 'git pull ...') before pushing again.hint: See the 'Note about fast-forwards' in 'git push --help' for details.chenjp@chenjpdeMacBook-Pro technician-biz-service$ git branch* chenjpmasterchenjp@chenjpdeMacBook-Pro technician-biz-service$ git statusOn branch chenjpYour branch and 'origin/chenjp' have diverged,and have 8 and 2 different commits each, respectively.(use "git pull" to merge the remote branch into yours)You have unmerged paths.(fix conflicts and run "git commit")Unmerged paths:(use "git add <file>..." to mark resolution)both modified: src/main/resources/config/spring/local/applicationContext-pigeon.xmlno changes added to commit (use "git add" and/or "git commit -a")chenjp@chenjpdeMacBook-Pro technician-biz-service$ git add .chenjp@chenjpdeMacBook-Pro technician-biz-service$ git statusOn branch chenjpYour branch and 'origin/chenjp' have diverged,and have 8 and 2 different commits each, respectively.(use "git pull" to merge the remote branch into yours)All conflicts fixed but you are still merging.(use "git commit" to conclude merge)Changes to be committed:modified: src/main/resources/config/spring/local/applicationContext-pigeon.xmlchenjp@chenjpdeMacBook-Pro technician-biz-service$ git commit -a -m 'resolve conflict'[chenjp 45eab62] resolve conflictchenjp@chenjpdeMacBook-Pro technician-biz-service$chenjp@chenjpdeMacBook-Pro technician-biz-service$chenjp@chenjpdeMacBook-Pro technician-biz-service$chenjp@chenjpdeMacBook-Pro technician-biz-service$chenjp@chenjpdeMacBook-Pro technician-biz-service$ git logcommit 45eab62cef9cc116403f65aa3b1f008f394a1259Merge: 160f108 41ec8e0Author: jinpeng.chen <22221cjp@163.com>Date: Fri May 8 18:35:26 2015 +0800resolve conflictcommit 160f1081dc209010ab4c894cb8c8c7ffc4c6541fAuthor: jinpeng.chen <22221cjp@163.com>Date: Fri May 8 17:16:41 2015 +0800update 技师周报commit 0c88ed90d6c2ede39dc77ce8be1b8caaeb34fe39Author: jinpeng.chen <22221cjp@163.com>Date: Thu May 7 19:31:12 2015 +0800丽人周报提交commit 41ec8e0b88c74792639458ad3ecb37ba608ba6e4Author: jinpeng.chen <22221cjp@163.com>Date: Fri May 8 17:16:41 2015 +0800chenjp@chenjpdeMacBook-Pro technician-biz-service$ git push origin HEAD:chenjpCounting objects: 30, done.Delta compression using up to 4 threads.Compressing objects: 100% (27/27), done.Writing objects: 100% (30/30), 2.49 KiB | 0 bytes/s, done.Total 30 (delta 15), reused 0 (delta 0)To git@code.dianpingoa.com:technician/technician-biz.git41ec8e0..45eab62 HEAD -> chenjpchenjp@chenjpdeMacBook-Pro technician-biz-service$
合并不同分支查看这个链接:
http://www.cnblogs.com/kym/archive/2010/08/12/1797937.html
创建分支很简单:git branch <分支名>
git checkout <分支名>
该语句和上一个语句可以和起来用一个语句表示:git checkout -b <分支名>
比如,如果要将开发中的分支(develop),合并到稳定分支(master),
首先切换的master分支:git checkout master。
然后执行合并操作:git merge develop。
如果有冲突,会提示你,调用git status查看冲突文件。
解决冲突,然后调用git add或git rm将解决后的文件暂存。
所有冲突解决后,git commit 提交更改。
分支衍合和分支合并的差别在于,分支衍合不会保留合并的日志,不留痕迹,而 分支合并则会保留合并的日志。
要将开发中的分支(develop),衍合到稳定分支(master)。
首先切换的master分支:git checkout master。
然后执行衍和操作:git rebase develop。
如果有冲突,会提示你,调用git status查看冲突文件。
解决冲突,然后调用git add或git rm将解决后的文件暂存。
所有冲突解决后,git rebase --continue 提交更改。
执行git branch -d <分支名>
如果该分支没有合并到主分支会报错,可以用以下命令强制删除git branch -D <分支名>
=============================
建立本地的dev分支追踪远程仓库的develop分支
git checkout –b dev origin/develop
git push origin HEAD:chenjp
==============================
origin 是远程仓库在本地的别名。因为每次输入一次远程仓库的url比较麻烦,所以就起个一个别名。如果新的仓库是在远程建立的,如oschina上,然后通过clone下来的。如果在clone下来的本地仓库中输入git remote -v可以查看
可以看到默认的别名就是origin,这个名字也好理解。因为origin本意是“原始的”,远程相对于本地的clone版本,的确是原始的。
但是如果仓库是在本地通过git init 建立的。这时候就没有一个远程仓库和本地对应。这时候就需要执行如下这个命令了。
git remote add origin git@xbc.me:wordpress.git
约定俗成,这里的别名依然叫origin。
但是现在一般都是在远程先建立,然后直接clone到本地。这样更省事。
git stash save '说一点这次stash保存内容'
git stash list
git stash pop stash{0} 弹出stash栈中的某一次临时保存
===================================================================
git init
git add .
git commit -am ‘first commit'
git remote add origin https://xxxxxxx
git remote -v
git remote rm origin //删除origin别名对应的远程仓库
ssh-keygen -t rsa -C 'you_email@email.com'
复制~/.ssh /rsa.pub 到github上配置一下
git pull —rebase origin master
git checkout -b new_branch
git checkout -b new_branch origin/branch1 //基于远程仓库的branch1创建本地分支new_branch
git stash 将本地工作临时保存
git stash save ‘descripe your work’
git stash list
git stash pop stash@{0}
git stash clear
git push origin HEAD:chenjp
git rebase master //将master合并到当前分支,保留master的提交记录
git branch 查看分支
git branch -D branch1
//基于某次提交创建分支----间接回到历史上某个版本
git branch branch_name fe873ac91
git push origin :branch-name //删除远程仓库分支
git branch -m old_branch new_branch //重命名分支
git cherry-pick [commit_bash] //将一个次提交应用到当前分支
//有时候rebase了其他分支,改变了当前分支之前的历史,push的时候会出错,这时候需要添加--force参数
git push —force origin HEAD:chenjp
git rm —cached filename //取消某个文件的跟踪
git rm —cached -r dir //取消某个目录的跟踪
git pull命令的作用是,取回远程主机某个分支的更新,再与本地的指定分支合并。它的完整格式稍稍有点复杂。
$ git pull <远程主机名> <远程分支名>:<本地分支名>
比如,取回origin主机的next分支,与本地的master分支合并,需要写成下面这样。
$ git pull origin next:master
如果远程分支是与当前分支合并,则冒号后面的部分可以省略。
$ git pull origin next
实际使用最好用git pull --rebase保留合并的历史
==========================git 故障处理========================
基于远程分支创建本地分支的时候,有时候会报这个错。
chenjp@chenjp ~/D/d/beauty-merchant-biz> git checkout -b dengyun.zhou origin/dengyun.zhoufatal: Cannot update paths and switch to branch 'dengyun.zhou' at the same time.Did you intend to checkout 'origin/dengyun.zhou' which can not be resolved as commit?chenjp@chenjp ~/D/d/beauty-merchant-biz>
原因是自己原来clone的时候,远程并没有这个分支,通过如下命令查看
chenjp@chenjp ~/D/d/beauty-merchant-biz> git branch -a* chenjpmasterremotes/origin/20150810-offlineremotes/origin/20151010-authorityremotes/origin/HEAD -> origin/masterremotes/origin/lightmergeremotes/origin/masterchenjp@chenjp ~/D/d/beauty-merchant-biz>
所以会报上面的错。解决方法,需要fetch下所有的远程分支。
chenjp@chenjp ~/D/d/beauty-merchant-biz> git fetch originremote: Counting objects: 892, done.remote: Compressing objects: 100% (486/486), done.remote: Total 892 (delta 364), reused 175 (delta 71)Receiving objects: 100% (892/892), 79.89 KiB | 0 bytes/s, done.Resolving deltas: 100% (364/364), completed with 21 local objects.From code.dianpingoa.com:beauty/beauty-merchant-bizd2b3d6b..ab0979c 20151010-authority -> origin/20151010-authority* [new branch] dengyun.zhou -> origin/dengyun.zhoud2b3d6b..84519c7 lightmerge -> origin/lightmerge* [new branch] shuang.he -> origin/shuang.hechenjp@chenjp ~/D/d/beauty-merchant-biz> git branch -a* chenjpmasterremotes/origin/20150810-offlineremotes/origin/20151010-authorityremotes/origin/HEAD -> origin/masterremotes/origin/dengyun.zhouremotes/origin/lightmergeremotes/origin/masterremotes/origin/shuang.hechenjp@chenjp ~/D/d/beauty-merchant-biz> git checkout -b dengyun.zhou origin/dengyun.zhouBranch dengyun.zhou set up to track remote branch dengyun.zhou from origin.Switched to a new branch 'dengyun.zhou'chenjp@chenjp ~/D/d/beauty-merchant-biz>
git忽略多层文件夹是经常的需求,在.gitignore忽略多层文件夹用:**
**/bin/Debug/
前面的两个*号代表任意多层上级文件夹
需要 git 1.8.2 及其以上的版本才支持