$ git merge feature1
Auto-merging readme.txt
CONFLICT (content): Merge conflict in readme.txt
Automatic merge failed; fix conflicts and then commit the result.
$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 2 commits.
#
# Unmerged paths:
# (use "git add/rm <file>..." as appropriate to mark resolution)
#
# both modified: readme.txt // 冲突了
#
no changes added to commit (use "git add" and/or "git commit -a")
Git is a distributed version control system.
Git is free software distributed under the GPL.
Git has a mutable index called stage.
Git tracks changes of files.
<<<<<<< HEAD
Creating a new branch is quick & simple.
=======
Creating a new branch is quick AND simple.
>>>>>>> feature1
Git用<<<<<<<,=======,>>>>>>>标记出不同分支的内容,我们修改如下后保存:
Creating a new branch is quick and simple.
推送的时候如果有人在你之前已经推送了,推送失败
$ git push origin dev
To git@github.com:michaelliao/learngit.git
! [rejected] dev -> dev (non-fast-forward)
error: failed to push some refs to 'git@github.com:michaelliao/learngit.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
因为你的小伙伴的最新提交和你试图推送的提交有冲突,解决办法也很简单,
Git已经提示我们,先用git pull把最新的提交从origin/dev抓下来,然后,在本地合并,解决冲突,再推送
$ git pull //抓去远程的分支的提交到本地
没有指定本地dev分支与远程origin/dev分支的链接,推送也会失败,所以首先我们需要建立本地分支和远程分支的联系
$ git branch --set-upstream dev origin/dev // 建立本地dev 分支和远程dev分支的联系
Branch dev set up to track remote branch dev from origin.
$ git tag v0.8 59bc1cb // 为commit id 为59bc1cb...的commit打上v0.8 标签
标签不是按时间顺序列出,而是按字母排序的。可以用git show <tagname>查看标签信息
还可以创建带有说明的标签,用-a指定标签名,-m指定说明文字:
$ git tag -a v0.1 -m "version 0.1 released" 3628164 // 为commit id为3628164...的commit打上v0.1 的标签注视内容是version 0.1 released
$ git tag v0.1 //可以查看标签的信息包括文字说明
还可以通过-s用私钥签名一个标签:
$ git tag -s v0.2 -m "signed version 0.2 released" fec145a
签名采用PGP签名,因此,必须首先安装gpg(GnuPG),如果没有找到gpg,或者没有gpg密钥对,就会报错:
gpg: signing failed: secret key not available
error: gpg failed to sign the data
error: unable to sign the tag
如果报错,请参考GnuPG帮助文档配置Key。