小记一些Github常用命令 :

  在一个项目中...

  假如要修补问题追踪系统上的 #53 问题。顺带说明下,Git 并不同任何特定的问题追踪系统打交道。这里为了说明要解决的问题,把新建的分支取名为 iss53。要新建并切换到该分支,运行 git checkout 并加上 -b 参数:

$ git checkout -b iss53
Switched to a new branch 'iss53' ====================================================
相当于执行 下面 2个命令:
  $ git branch iss53
  $ git checkout iss53

有必要作些测试,确保修补是成功的,然后回到 master 分支并把它合并进来,然后发布到生产服务器。用 git merge 命令来进行合并:修复完成后,合并到主干,

执行下面语句;

$ git checkout master
$ git merge hotfix
Updating f42c576..3a0874c
Fast-forward
README | -
file changed, deletion(-) ================有冲突的合并,总是不可避免================ $ git merge 分支名
Auto-merging index.html
CONFLICT (content): Merge conflict in index.html Automatic merge failed; fix conflicts and then commit the result.
Git 作了合并,但没有提交,它会停下来等你解决冲突。要看看哪些文件在合并时发生冲突,可以用 git status 查阅:
$ git status
On branch master
You have unmerged paths.
(fix conflicts and run "git commit") Unmerged paths:
(use "git add <file>..." to mark resolution) both modified: index.html no changes added to commit (use "git add" and/or "git commit -a")

任何包含未解决冲突的文件都会以未合并(unmerged)的状态列出。Git 会在有冲突的文件里加入标准的冲突解决标记,可以通过它们来手工定位并解决这些冲突。可以看到此文件包含类似下面这样的部分:

<<<<<<< HEAD
<div id="footer">contact : email.support@github.com</div>
=======
<div id="footer">
please contact us at support@github.com
</div>
>>>>>>> iss53

可以看到 ======= 隔开的上半部分,是 HEAD(即 master 分支,在运行 merge 命令时所切换到的分支)中的内容,下半部分是在 iss53 分支中的内容。解决冲突的办法无非是二者选其一或者由你亲自整合到一起。比如你可以通过把这段内容替换为下面这样来解决:

<div id="footer">
please contact us at email.support@github.com
</div>

这个解决方案各采纳了两个分支中的一部分内容,而且我还删除了 <<<<<<<,======= 和 >>>>>>> 这些行。在解决了所有文件里的所有冲突后,运行 git add 将把它们标记为已解决状态(译注:实际上就是来一次快照保存到暂存区域。)。因为一旦暂存,就表示冲突已经解决。如果你想用一个有图形界面的工具来解决这些问题,不妨运行 git mergetool,它会调用一个可视化的合并工具并引导你解决所有冲突:

$ git mergetool

This message is displayed because 'merge.tool' is not configured.
See 'git mergetool --tool-help' or 'git help config' for more details.
'git mergetool' will now attempt to use one of the following tools:
opendiff kdiff3 tkdiff xxdiff meld tortoisemerge gvimdiff diffuse diffmerge ecmerge p4merge araxis bc3 codecompare vimdiff emerge
Merging:
index.html Normal merge conflict for 'index.html':
{local}: modified file
{remote}: modified file
Hit return to start merge resolution tool (opendiff):

如果不想用默认的合并工具(Git 为我默认选择了 opendiff,因为我在 Mac 上运行了该命令),你可以在上方"merge tool candidates"里找到可用的合并工具列表,输入你想用的工具名。我们将在第七章讨论怎样改变环境中的默认值。

退出合并工具以后,Git 会询问你合并是否成功。如果回答是,它会为你把相关文件暂存起来,以表明状态为已解决。

再运行一次 git status 来确认所有冲突都已解决:

$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage) modified: index.html

如果觉得满意了,并且确认所有冲突都已解决,也就是进入了暂存区,就可以用 git commit 来完成这次合并提交。提交的记录差不多是这样:

Merge branch 'iss53'

Conflicts:
index.html
#
# It looks like you may be committing a merge.
# If this is not correct, please remove the file
# .git/MERGE_HEAD
# and try again.
#
提交过后,可以把无用的分支删除了....
删除分支的命令:
$ git branch -d 分支名
Deleted branch hotfix (was 3a0874c).

=================================================================================

winXP / GitHub/

git pull收到了conflict,怎么merge?

<<<<<<< HEAD

本地文件

=======

远程pull下来的文件

>>>>>>> 7bb3c50a1d13049ed1187a702ed6f6cbf4f91453

我的做法是手工编辑有conflict的文件,改成我想要的内容,然后commit,这样有问题吗?

但是commit的时候,报错:

D:\wamp\www\TMS\tms>git commit -m 'all'
U view/login.html
error: 'commit' is not possible because you have unmerged files.
hint: Fix them up in the work tree,
hint: and then use 'git add/rm <file>' as
hint: appropriate to mark resolution and make a commit,
hint: or use 'git commit -a'.
fatal: Exiting because of an unresolved conflict. D:\wamp\www\TMS\tms> 是不是应该用git进行merge,而不是手工编辑。。。。 但是显然git merge时不是merge不了,才把conflict放在一个文件里的啊 。。。找不到头绪 -------------------------------- 解决方法如下(问题留在这里,帮助后来的人) 我应该手工编辑好conflict之后再add,再commit,再push。 D:\wamp\www\TMS\tms>git add view\login.html D:\wamp\www\TMS\tms>git commit -m 'login.html'
[master d0e560d] 'login.html' D:\wamp\www\TMS\tms>git push

  http://git-scm.com/book/zh/v1

      

Github 常用命令的更多相关文章

  1. Linux 使用 github 常用命令

    Linux 使用 github  常用命令 今天整理一下常用的 github 命令,自己只是一个编程小白,有些地方可能做的不是很好,仅仅用作自己的学习使用. 创建一个文件夹用于存放github仓库 m ...

  2. github常用命令

    全局配置 git config --global user.name "lewiscutey"git config --global user.email "lewisc ...

  3. git(github)常用命令

    安装git sudo apt-get install git 显示git版本 git version 显示system属性,对应为/etc/gitconfig文件的内容 git config --sy ...

  4. GitHub常用命令及使用

    GitHub使用介绍 摘要: 常用命令: git init 新建一个空的仓库git status 查看状态git add . 添加文件git commit -m '注释' 提交添加的文件并备注说明gi ...

  5. GIt/Github常用命令

    1)git init:初始化本地仓库 2)创建文件:touch read.txt 3)当操作本地的文件时,使用常用的命令,如(mv,ls..)就可以操作,当操作暂存区的文件时需要在命令前家git,并且 ...

  6. GitHub 常用命令使用介绍(新同学入门)

    经济在不断发展,社会在不断进步,以往的互联网在现在看来都可以称为传统互联网了,因为技术不断的在突破和革新. 本文主要介绍一下版本管理工具,我猜测很多人还是用SVN.CVS或者Resion,但是,今天我 ...

  7. Github常用命令【转】

    本地仓库(local repository) 创建一个本地仓库的流程: 为本地仓库创建一个目录 在目录中执行 git init 对本地仓库所做的改变(例如添加.删除文件等)首先加入到本地仓库的 Ind ...

  8. github常用命令汇总

    创立版本库 mkdir Baiducd Baidugit init SSHssh-keygen -t -rsa -C "TaylorApril947939@gmail"(在gith ...

  9. Git与github常用命令

    Git项目与github建立联系 首先,需要在github上建立一个repository mkdir github-project cd github-project git init 此时githu ...

随机推荐

  1. SharePoint各版本信息

    参考网页http://blogs.msdn.com/b/erica/archive/2013/05/30/sharepoint-server-2010-version-reference.aspx

  2. 【.NetRemoting-2】2015.09.17

    [Remoting架构] [1]是.NetFramework的一个重要组成 [2]框架的两个重要特性 [A]基本实现[B]可扩展/可定制 [各个组成部分] [1][客户端,客户端应用程序域] [组成] ...

  3. ckplayer 项目实际应用代码整理,支持标清,高清,超清切换!

    ckplayer是个免费,小巧,功能强大的视频播放器,前段时间有个项目需要做个收费视频播放的功能,于是就用了ck,目前项目已经弄完,完美支持pc和手机端的播放,重要的是可以支持清晰度切换,最后加了个是 ...

  4. 利用jQuery实现的Ajax 验证用户名是否存在

    异步刷新实现方式有多种,也可以借助JS的多种框架,下面是使用jQuery框架实现的AJAX 验证用户名是否存在 jQuery.ajax概述 HTTP 请求加载远程数据. 通过jQuery 底层 AJA ...

  5. PNG图片小结

    PNG: 便携式网络图形(Portable Network Graphics,PNG)是一种无损压缩的位图图形格式,支持索引.灰度.RGB三种颜色方案以及Alpha通道等特性.PNG的开发目标是改善并 ...

  6. WDLINUX (Centos5.8) 安装 soap

    CENTOS5.8  PHP5.2.17 [PHP5.3.27版的看这里] WDLINUX (centos) 安装 soap====================================== ...

  7. 翻译题(map使用)

    What Are You Talking About 点我 Problem Description Ignatius is so lucky that he met a Martian yesterd ...

  8. codeforces 519A. A and B and Chess,

    A. A and B and Chess time limit per test 1 second memory limit per test 256 megabytes input standard ...

  9. AdminCMD

    program AdminCMD; {$APPTYPE CONSOLE} uses Windows, ShellApi, SysUtils; function RunAsAdmin(const iEx ...

  10. 【安装SQLserver2008R2 出现错误,临时类 result=1】

    去服务中,停止此  AliWorkbench Safe service 服务....玛德,千牛工作台.垃圾