美文网首页
git多人协作-常用命令

git多人协作-常用命令

作者: 马丁路德东 | 来源:发表于2018-08-21 10:22 被阅读0次

教程源自 廖雪峰老师的博客,在此表示感谢,知识的先行者。

查看远程仓库信息 git remote -v是可以查看更多信息

$ git remote

推送分支,将本地的master推送到远程的origin

$ git push origin master

当你的小伙伴从远程库clone时,默认情况下,你的小伙伴只能看到本地的master分支。但是一般开发是在dev分支上的.
你的小伙伴要在dev分支上开发,就必须创建远程origin的dev分支到本地,于是他用这个命令创建本地dev分支:

$ git checkout -b dev origin/dev

一旦你和你的小伙伴同时对一个文件进行更改,那样你们最后一个提交的同学就会提交不上去。

$ git push origin dev
To 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. 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.

git 提示你 只用git pull进行对文件的拉取。
有时候git pull也会失败,因为本地没有与远程仓库对应的分支

$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> dev

如果git pull提示no tracking information,则说明本地分支和远程分支的链接关系没有创建,用命令git branch --set-upstream-to <branch-name> origin/<branch-name>。

$ git branch --set-upstream-to=origin/dev dev
Branch 'dev' set up to track remote branch 'dev' from 'origin'.

pull 成功之后 ,手动修改冲突,然后再提交,再push;

对此,解决冲突提交之后,git log 的提交历史会变得不好判断,
rebase操作可以把本地未push的分叉提交历史整理成直线;
rebase的目的是使得我们在查看历史提交的变化时更容易,因为分叉的提交需要三方对比。

$ git rebase

git tag标签 :在当前分支上打标签 v1.0。标签默认会打到最近一次的commit上。

$ git tag v1.0

查看提交日志$ git log --pretty=oneline --abbrev-commit,再某个commit上打tag

$ git log --pretty=oneline --abbrev-commit
12a631b (HEAD -> master, tag: v1.0, origin/master) merged bug fix 101
4c805e2 fix bug 101
e1e9c68 merge with no-ff
f52c633 add merge
cf810e4 conflict fixed
5dc6824 & simple
14096d0 AND simple
b17d20e branch test
d46f35e remove test.txt
b84166e add test.txt
519219b git tracks changes
e43a48b understand how stage works
1094adb append GPL
e475afc add distributed
eaadf4e wrote a readme file

比方说要对add merge这次提交打标签,它对应的commit id是f52c633,敲入命令:

$ git tag v0.9 f52c633

查看标签

$ git tag

注意,标签不是按时间顺序列出,而是按字母排序的。可以用git show <tagname>查看标签

$ git show v0.9
commit f52c63349bc3c1593499807e5c8e972b82c8f286 (tag: v0.9)
Author: Michael Liao <askxuefeng@gmail.com>
Date:   Fri May 18 21:56:54 2018 +0800

    add merge

diff --git a/readme.txt b/readme.txt
...

还可以创建带有说明的标签,用-a指定标签名,-m指定说明文字:

$ git tag -a v0.1 -m "version 0.1 released" 1094adb

tag的其他操作
命令git push origin <tagname>可以推送一个本地标签;

命令git push origin --tags可以推送全部未推送过的本地标签;

命令git tag -d <tagname>可以删除一个本地标签;

命令git push origin :refs/tags/<tagname>可以删除一个远程标签。

相关文章

  • git学习记录

    工作区{ } 版本库{ } git常用命令 多人协作

  • git多人协作-常用命令

    教程源自 廖雪峰老师的博客,在此表示感谢,知识的先行者。 查看远程仓库信息 git remote -v是可以查看...

  • Git 多人协作

    git clone XXXXX 下载项目 git remote -v 查看当前的远程库git remote rem...

  • git | 多人协作

    当你从远程仓库克隆时,实际上Git自动把本地的master分支和远程的master分支对应起来了,并且,远程仓库的...

  • Git多人协作

    一. git仓库添加协作者 进入某远端仓库setting–>collaborators–>search and a...

  • git多人协作

    当你从远程仓库克隆时,实际上Git自动把本地的master分支和远程的master分支对应起来了,并且,远程仓库的...

  • Git | 多人协作

    多人协作的工作模式通常是这样: 首先,可以试图用git push origin 推送自己的修改; 如果推送失败,...

  • git 常用命令汇总

    一、git常用命令: 二、团队协作git操作流程: 三、git工作流 更多咨询请关注:1、Git 汇总2、VUE3...

  • Git的一些常用命令

    git的一些常用命令和协作流程 1. 远程仓库相关命令 命令作用$ git clone克隆仓库$ git remo...

  • 流程

    GIT常用命令 =====================团队协作开发 1.基础流程操作1)首先创建中央仓库:可以...

网友评论

      本文标题:git多人协作-常用命令

      本文链接:https://www.haomeiwen.com/subject/wekdiftx.html