欢迎来到Doc100.Net免费学习资源知识分享平台!
您的位置:首页 > 程序异常 >

2013.11.14 ——— git学习之旁支操作

更新时间: 2014-01-05 02:33:57 责任编辑: Author_N1

 

2013.11.14 ——— git学习之分支操作
2013.11.14 ——— git学习之分支操作

git branch //显示当前分支

git branch test //新建一个test的本地分支

git branch -d test //删除test分支

git checkout -b dev origin/dev //检出一个远程分支的本地分支
或者
git checkout --track origin/dev //这个默认本地分支名字为dev 上面的可以改变名字

git checkout XXX //切换分支

git checkout -b test //新建并切换的test本地分支





问题1、在master上面的一个commit,但是应该是在dev上修改的,修改错了,这个时候 需要把master的commit移到dev上来,总不能重新修改吧



git checkout master
git log
$ git log
commit ec8c07e36327c2418b7774cfbcd997d9fb178c95
Author: lipeng <lipeng@xunlei.com>
Date:   Thu Nov 14 10:53:49 2013 +0800

    lipeng update 'recommend' expandableListView

commit e7d10875796d32b34b60efe3bfd4178b5f102c2f
Author: xuyong <suyong@xunlei.com>
Date:   Wed Nov 13 16:42:23 2013 +0800

    恢复到merge dev分支新搜索界面时落了些东西

commit 13c4fda4305e658865a99ca3d4988e3409ecf589
Author: xuyong <suyong@xunlei.com>
Date:   Wed Nov 13 16:19:04 2013 +0800

    恢复到merge dev分支新搜索界面之前
然后 复制下你要移动的那个commit ec8c07e36327c2418b7774cfbcd997d9fb178c95

git checkout dev
git cherry-pick ec8c07e36327c2418b7774cfbcd997d9fb178c9

这样就ok了

问题二:master已经的那个commit已经复制过去了 但是master上面依然还有那个commit,我们需要删除这个commit

git checkout master
git reset HEAD~  //删除第一个commit ~后面可以跟数字 表示最近的几次提交
git log //发现最近的一次提交没有了
git status //如下 发现暂存区里面还有很多东西
# On branch master
# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   PhoneKankan/res/layout/fragment_recommend.xml
#       modified:   PhoneKankan/res/layout/home_video_gridview.xml
#       modified:   PhoneKankan/res/layout/video_image_item.xml
#       modified:   PhoneKankan/src/com/kankan/phone/recommend/RecommendFragmen
.java
#       deleted:    PhoneKankan/src/com/kankan/phone/recommend/VideoGridView.ja
a
#       modified:   PhoneKankan/src/com/kankan/phone/recommend/VideoGroupListVi
wAdapter.java
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       PhoneKankan/res/layout/home_video_gridview_title.xml
#       PhoneKankan/src/com/kankan/phone/recommend/MyGridView.java
no changes added to commit (use "git add" and/or "git commit -a")

git checkout -f  //取消所有暂存区修改

git status  //新加的没有跟踪的文件 还是存在的 需要手动删除下

# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       PhoneKankan/res/layout/home_video_gridview_title.xml
#       PhoneKankan/src/com/kankan/phone/recommend/MyGridView.java
nothing added to commit but untracked files present (use "git add" to track)


$ rm PhoneKankan/res/layout/home_video_gridview_title.xml

Sun@COSTARTER /e/Project/kankan (master)
$ rm PhoneKankan/src/com/kankan/phone/recommend/MyGridView.java

Sun@COSTARTER /e/Project/kankan (master)
$ git status
# On branch master
nothing to commit, working directory clean

另外 简单起见 也可以使用
git reset --hard HEAD~

会将最新的1次提交全部重置,就像没有提交过一样。

上一篇:上一篇
下一篇:下一篇

 

随机推荐程序问答结果

 

 

如对文章有任何疑问请提交到问题反馈,或者您对内容不满意,请您反馈给我们DOC100.NET论坛发贴求解。
DOC100.NET资源网,机器学习分类整理更新日期::2014-01-05 02:33:57
如需转载,请注明文章出处和来源网址:http://www.doc100.net/bugs/t/11499/
本文WWW.DOC100.NET DOC100.NET版权所有。