git 带着修改checkout 到其他分支
来源:互联网 发布:淘宝网返利链接的制作 编辑:程序博客网 时间:2024/06/07 16:16
正常情况下,如果所在分支有修改想工切换到其他分支就会报错:
zhangjie$ git checkout mastern
error: Your local changes to the following files would be overwritten by checkout:
first
Please commit your changes or stash them before you can switch branches.
Aborting
比如我有如下文件
zhangjie$ ls
README.md first mn
zhangjie$ git diff
diff --git a/first b/first
index 9465807..f9c4725 100644
--- a/first
+++ b/first
@@ -1,4 +1,3 @@
-it i
oi
我的分支为
git branch
masn
* master
mastern
mn
从上面可看出我有一个分支名为mn,也有一个文件名为mn,此时我也有修改,我执行checkoutzhangjie$ git checkout mn
M first
Switched to branch 'mn'
Your branch is up-to-date with 'origin/master'.
zhangjiedeMacBook-Pro:gitLearning zhangjie$ git status
On branch mn
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: first
no changes added to commit (use "git add" and/or "git commit -a")
zhangjiedeMacBook-Pro:gitLearning zhangjie$ git diff
diff --git a/first b/first
index 9465807..f9c4725 100644
--- a/first
+++ b/first
@@ -1,4 +1,3 @@
-it i
oi
可以看到我在master里的修改没有提交,没有stash,但是我checkout 到了mn这个分支,并且把在master的修改带过来了。
我在mn分支提交后再切回到master,master里没有修改了
zhangjiedeMacBook-Pro:gitLearning zhangjie$ git commit -m 'd ling'
[mn 317c0c3] d ling
1 file changed, 1 deletion(-)
zhangjiedeMacBook-Pro:gitLearning zhangjie$ git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
zhangjiedeMacBook-Pro:gitLearning zhangjie$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
zhangjiedeMacBook-Pro:gitLearning zhangjie$
比较奇妙,不仅在有修改的时候能切换分支,且可以把修改的内容merge过去,感觉是因为分支名和文件名相同,被认为是checkout file,但实际执行的却是checkout branch,但是如果到新的分支,原来的内容就丢失了,所以就把原分支的修改merge到新分支了。有谁明白也不吝赐教。- git 带着修改checkout 到其他分支
- git checkout 远程分支
- git checkout切换分支
- git rebase & merge 将其他分支的修改合并到当前分支
- git checkout之二 切换到分支和文件覆盖
- checkout 到bit/master分支
- git 切换分支时的 git checkout
- git 将一个分支的修改同步到另一个分支
- git checkout:从分支或者索引中检索文件到当前工作目录
- Git使用手册:git checkout 创建分支、切换分支
- git checkout 远程分支失败的问题解决
- git用其他分支覆盖到另一个分支 and 删除远程分支
- git分支操作(git branch;git checkout;git checkout -b;git merge;git merge --abort)
- 使用git的cherry-pick命令把其他分支的某个commit合并到当前分支
- git学习笔记-7 git checkout 切换分支
- Git 常用操作(九) git checkout 与分支切换
- git历史版本修改合并到主分支
- git修改远程分支
- OpenCV-Python[第三章]——图像格式及操作方法
- raft到底是两段提交还是一段提交,以及raft的不确定性
- 计算机网络实验——VLAN划分
- 【CCF 俄罗斯方块】
- 李理:详解卷积神经网络
- git 带着修改checkout 到其他分支
- 洛谷 1144
- css布局左右定宽,中间自适应
- c语言
- 表单验证等其他公用js方法
- 学年论文_车对车超宽带无线通信技术研究
- struts配置结果以及Action中关于 request 与 session 的注入
- IP地址分类
- jQuery中li的变化