Github 常用命令
小记一些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-forwardREADME | 1 -1 file changed, 1 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.htmlno 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 mergetoolThis 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.htmlNormal 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.htmlD:\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 常用命令相关推荐
- GitHub常用命令
GitHub常用命令 转载于:https://www.cnblogs.com/dancser/p/4326524.html
- GitHub常用命令及使用
GitHub使用介绍 摘要: 常用命令: git init 新建一个空的仓库 git status 查看状态 git add . 添加文件 git commit -m '注释' 提交添加的文件并备注说 ...
- GitHub常用命令及常见问题解决方案
常用命令 git init 在本地新建一个repo,进入一个项目目录,执行git init,会初始化一个repo,并在当前文件夹下创建一个.git文件夹. git clone 获取一个url对应的远程 ...
- GIt/Github常用命令
1)git init:初始化本地仓库 2)创建文件:touch read.txt 3)当操作本地的文件时,使用常用的命令,如(mv,ls..)就可以操作,当操作暂存区的文件时需要在命令前家git,并且 ...
- Git结合GitHub常用命令
简介 GIT 学习手册简介 这是 Git 学习参考手册.目的是为学习与记忆 Git 使用中最重要.最普遍的命令提供快速翻阅. 这些命令以你可能需要的操作类型划分,并且将提供日常使用中需要的一些常用的命 ...
- Git版本控制软件结合GitHub常用命令学习手册
编程技术2015-1-16TECHUG1条评论 我们发布了很多Git相关的文章,有系列教程(<Pro Git系列>),也有各种独门绝技(<让你的Git水平更上一层楼的10个小贴士&g ...
- 第一篇技术类博文:Git以及GitHub常用命令记录与总结【Rico】(已完结!)
Git身为目前世界上最先进的分布式版本控制系统,本菜鸟也是刚刚开始学习,目前上手还是有点难度,记录下来,希望更多的初学者看到,也可以让自己需要用到的适合可以方便的查阅. 1.Git的安装 Git最早使 ...
- github常用命令总结
一.创建仓库 cmd窗口打开/cd 进入你的工作目录 1.创建命令 git init 2.配置用户名和邮箱: git config --global user.name '你自己的github用户名' ...
- gitHub常用命令笔记
在github上创建仓库: Create a new repository on the command line touch README.md git init git add README.md ...
最新文章
- 蚂蚁财富联手百会CRM全面升级金融服务
- day3 python 函数
- 机器学习之——学习率
- Python基础之:数字字符串和列表
- Angular单元测试里pipe的mock设计
- select、poll、epoll 比较
- [转]java 输出流转输入流
- 程序员面试金典——番外篇之约瑟夫问题2
- Metropolis Hastings MCMC when the proposal and target have differing support
- STL:STL各种容器的使用时机详解
- java filechannel 并发_java.nio中的Channel系列(2)-FileChannel与零拷贝原理
- 单片机跑马灯源代码+仿真
- 文达仓库管理软件 v5.32 网络版 怎么用
- SAS更新sid的方法,简单有效,sid最新可到2022年3月
- 统计学中p值计算公式_统计学中P值的计算!
- deepin安装教程(deepin安装教程不用u盘)
- 最美证件照工作室需要买什么东西
- Android moudle库使用aar的方法
- 【ChatGPT】ChatGPT使用指南——句词分类
- SRS系列一——实现RTMP直播