在修改这博客样式时,发现我是在主分支上修改的,并且已经commit记录了。想切换回临时分支feature_1上开发;加上现在格式化index.html时,解析时报错。借这个时机开始切换分支。

webStorm


####文件状态的颜色标记

  • 红色代表要加到追踪文件
  • 蓝色代表暂存区文件有修改
  • 青绿色代表文件要提交

步骤


  1. 在一分支a里工作一半,没commit。git stash,保存工作区和暂存到堆栈
  2. 切换到另一老分支b,

  3. git stash apply –index ,将堆栈内容移动这边,但有个文件状态是修改,b的HEAD中没有这个文件,现在Git在文件系统中保留这个文件x,提醒你添加;还有问题是,命令效果并没达到预期的,现在堆栈文件都提醒你Commit,也就是说东西都到了暂存,除了提醒你添加的那个。

  4. 取消应用堆栈,于是调用命令git stash show -p git apply -R。发现这个命令效果只是将HEAD内容取到工作区,暂存不管。于是问题还是没解决。
  5. 在webStorm中add文件x了,发现它是红色的,接下来。一种方案是add工作区所有文件,可是刚才不应该add

  6. 一种是将暂存东西放到文件目录,通过webStorm发现不可行,那个revert命令取的还是Head

  7. 一种是再冒险,合并分支。选择合并分支后,在vim中编辑注释时,返回报错了,合并没成功。对这步结果一直不解。现在status:staged 堆栈文件+刚才添加的文件x都不见了。被另外写内容替代?文件x好像只有这样解释。那什么东西来替代?

  8. 继续提交,提醒切换成功

  9. 在webStorm中revert两个工作区文件

  10. git stash apply

  11. git commit -a -m “xx”

相关代码


$ git checkout feature_1
error: Your local changes to the following files would be overwritten by checkout:
	_posts/2014-2-10-Js跨域.md
	index.html
Please, commit your changes or stash them before you can switch branches.
Aborting
$ git status
# On branch 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:   _includes/themes/sprying/post.html
#	modified:   "_posts/2014-2-10-Js\350\267\250\345\237\237.md"
#	modified:   "_posts/2014-2-6-Git\345\273\272\347\253\231-jekyll\345\217\202\350\200\203.md"
#	modified:   assets/themes/sprying/css/style.css
#	modified:   index.html
#
no changes added to commit (use "git add" and/or "git commit -a")
$ git checkout -- index.html
$ git stash
Saved working directory and index state WIP on master: 117e588 to add for last committing
HEAD is now at 117e588 to add for last committing
$ git checkout feature_1
Switched to branch 'feature_1'
$ git stash list
stash@{0}: WIP on master: 117e588 to add for last committing
$ git stash apply --index
CONFLICT (modify/delete): _posts/2014-2-10-Js跨域.md deleted in Updated upstream and modified in Stashed changes. Version Stashed changes of _posts/2014-2-10-Js跨域.md left in tree.
Index was not unstashed.
$ git status
# On branch feature_1
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#	modified:   _includes/themes/sprying/post.html
#	modified:   "_posts/2014-2-6-Git\345\273\272\347\253\231-jekyll\345\217\202\350\200\203.md"
#	modified:   assets/themes/sprying/css/style.css
#
# Unmerged paths:
#   (use "git reset HEAD <file>..." to unstage)
#   (use "git add/rm <file>..." as appropriate to mark resolution)
#
#	deleted by us:      "_posts/2014-2-10-Js\350\267\250\345\237\237.md"
#
$ git merge master
error: 'merge' 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.
$ git add _posts/2014-2-10-Js\350\267\250\345\237\237.md
fatal: pathspec '_posts/2014-2-10-Js350267250345237237.md' did not match any files
$ git stash show -p | git apply -R /*还原stash*/
<stdin>:81: trailing whitespace.
看了[JavaScript跨域总结与解决办法](http://www.cnblogs.com/rainman/archive/2011/02/20/1959325.html)(*绕过防火墙,将Js加载到你浏览的页面,Js再open个window,你一不小心,在里面浏览文件,文件就泄密了。现在1. 跨域一般指的是在访问iframe中内容的Dom或Js变量时出现的;**不支持跨域,指的是**:还有父页面不能访问比如想访问iframe页面的window和document,测试发现,`document.getElementByTagname('iframe')[0].content3、iframe与location.hash,涉及三个页面,父页面通过hash访问一级iframe,一级iframe通过hash返回数据岛二子页面就可以用 opener.method(); 或者 new opener()的方式跨域调用父页的方法了.同样的.子页面可以在需要这是google的工程师率先发现的ie6 7的漏洞. 介于ie6 7不打算修补这个漏洞的事实.所以可以作为跨域通信的解决方案之一. 但要妥善用之.否则有很大安全隐患.
warning: 1 line adds whitespace errors.
$ git status
# On branch feature_1
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#	modified:   _includes/themes/sprying/post.html
#	modified:   "_posts/2014-2-6-Git\345\273\272\347\253\231-jekyll\345\217\202\350\200\203.md"
#	modified:   assets/themes/sprying/css/style.css
#
# Unmerged paths:
#   (use "git reset HEAD <file>..." to unstage)
#   (use "git add/rm <file>..." as appropriate to mark resolution)
#
#	deleted by us:      "_posts/2014-2-10-Js\350\267\250\345\237\237.md"
#
# 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:   _includes/themes/sprying/post.html
#	modified:   "_posts/2014-2-6-Git\345\273\272\347\253\231-jekyll\345\217\202\350\200\203.md"
#	modified:   assets/themes/sprying/css/style.css
#
$ git diff --cached
diff --git a/_includes/themes/sprying/post.html b/_includes/themes/sprying/post.html
index de2c740..5787b14 100644
--- a/_includes/themes/sprying/post.html
+++ b/_includes/themes/sprying/post.html
/*结论:还原操作,只是将Head内容取到工作区,暂存还不变*/
/*通过webStorm的UI界面,add Js跨域这篇文章*/
$ git status
# On branch feature_1
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#	modified:   _includes/themes/sprying/post.html
#	new file:   "_posts/2014-2-10-Js\350\267\250\345\237\237.md"
#	modified:   "_posts/2014-2-6-Git\345\273\272\347\253\231-jekyll\345\217\202\350\200\203.md"
#	modified:   assets/themes/sprying/css/style.css
#
# 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:   _includes/themes/sprying/post.html
#	modified:   "_posts/2014-2-6-Git\345\273\272\347\253\231-jekyll\345\217\202\350\200\203.md"
#	modified:   assets/themes/sprying/css/style.css
#
$ git commit -m "checkout branch"
[feature_1 7784f75] checkout branch
 3 files changed, 14 insertions(+), 3 deletions(-)
 create mode 100644 "_posts/2014-2-10-Js\350\267\250\345\237\237.md"
$ git merge master
Removing _posts/core-samples/2011-12-29-jekyll-introduction.md
/*vim中编辑注释,不知是不是我vim编辑器配置问题,下面出现error*/
error: There was a problem with the editor 'vi'.
Not committing merge; use 'git commit' to complete the merge.
$ git merge master
fatal: You have not concluded your merge (MERGE_HEAD exists).
Please, commit your changes before you can merge.
$ git status
# On branch feature_1
# All conflicts fixed but you are still merging.
#   (use "git commit" to conclude merge)
#
# Changes to be committed:
#
#	new file:   "_posts/2013-10-30-Git\350\277\233\351\230\266.md"
#	deleted:    _posts/core-samples/2011-12-29-jekyll-introduction.md
#	new file:   assets/images/article/18333fig0327-tn2.png
#	new file:   assets/images/article/18333fig0329-tn3.png
#	new file:   assets/images/article/18333fig0330-tn4.png
#	new file:   assets/images/article/200912171261054909028.png
#	new file:   assets/images/article/200912171261055506012.png
#	new file:   assets/images/article/2009121712610555060121.png
#	modified:   assets/themes/sprying/js/sprying.js
#	modified:   index.html
#
# 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:   "_posts/2014-2-6-Git\345\273\272\347\253\231-jekyll\345\217\202\350\200\203.md"
#	modified:   assets/themes/sprying/css/style.css
#
/*合并后post.html不见了,估计快进自动合并到HEAD中;这个合并很奇怪。*/
[feature_1 b3c0847] Merge branch 'master' into feature_1
$ git status
# On branch feature_1
# 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:   "_posts/2014-2-6-Git\345\273\272\347\253\231-jekyll\345\217\202\350\200\203.md"
#	modified:   assets/themes/sprying/css/style.css
#
no changes added to commit (use "git add" and/or "git commit -a")
/*webStorm revert两个文件*/
$ git status
# On branch feature_1
nothing to commit, working directory clean
$ git stash apply
# On branch feature_1
# 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:   _includes/themes/sprying/post.html
#	modified:   "_posts/2014-2-10-Js\350\267\250\345\237\237.md"
#
no changes added to commit (use "git add" and/or "git commit -a")
$ git status
# On branch feature_1
# 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:   _includes/themes/sprying/post.html
#	modified:   "_posts/2014-2-10-Js\350\267\250\345\237\237.md"
#
no changes added to commit (use "git add" and/or "git commit -a")
$ git commit -a -m ""
Aborting commit due to empty commit message.
$ git status
# On branch feature_1
# 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:   _includes/themes/sprying/post.html
#	modified:   "_posts/2014-2-10-Js\350\267\250\345\237\237.md"
#
no changes added to commit (use "git add" and/or "git commit -a")
$ git commit -a -m "xx"
[feature_1 dde0e0f] xx
 2 files changed, 37 insertions(+), 36 deletions(-)
 rewrite "_posts/2014-2-10-Js\350\267\250\345\237\237.md" (97%)
$ git checkout master
Switched to branch 'master'
$ git stash apply
# On branch 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:   _includes/themes/sprying/post.html
#	modified:   "_posts/2014-2-10-Js\350\267\250\345\237\237.md"
#	modified:   "_posts/2014-2-6-Git\345\273\272\347\253\231-jekyll\345\217\202\350\200\203.md"
#	modified:   assets/themes/sprying/css/style.css
#
no changes added to commit (use "git add" and/or "git commit -a")
分享到: