2013.11.14 ——— git学习之分支操作
2013.11.14———git学习之分支操作
git branch //显示当前分支 git branch -a //显示远程仓库的所有分支 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 <[email protected]> Date: Thu Nov 14 10:53:49 2013 +0800 lipeng update 'recommend' expandableListView commit e7d10875796d32b34b60efe3bfd4178b5f102c2f Author: xuyong <[email protected]> Date: Wed Nov 13 16:42:23 2013 +0800 恢复到merge dev分支新搜索界面时落了些东西 commit 13c4fda4305e658865a99ca3d4988e3409ecf589 Author: xuyong <[email protected]> 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次提交全部重置,就像没有提交过一样。
相关推荐
baolen 2020-08-15
炼金术士lee 2020-08-15
huangchunxia 2020-08-07
lljhi0 2020-07-21
huangchunxia 2020-07-08
zhangxing 2020-07-05
ArkShen 2020-07-05
nebulali 2020-07-05
兄dei努力赚钱吧 2020-09-06
formula 2020-11-12
huhongfei 2020-11-05
乾坤一碼農 2020-10-27
liumengyanysu 2020-10-22
E哥的aws认证攻略 2020-10-15
tianyafengxin 2020-10-08
guying 2020-10-05