[心缘地方]同学录
首页 | 功能说明 | 站长通知 | 最近更新 | 编码查看转换 | 代码下载 | 常见问题及讨论 | 《深入解析ASP核心技术》 | 王小鸭自动发工资条VBA版
登录系统:用户名: 密码: 如果要讨论问题,请先注册。

[备忘]git里,未追踪的文件,pull冲突,stash -u后,如何apply的问题。

上一篇:[备忘]git删除.classpath文件
下一篇:[备忘]解决“Dynamic Web Module 3.0 requires Java 1.6 or newer.”错误

添加日期:2015/8/24 19:54:57 快速返回   返回列表 阅读6033次
问:两个人添加了同一个文件,A先push了,B在pull的时候,冲突,怎么搞?
---------------
答:git stash -u ,-u是包含unstarcked文件的意思。

问:恩,B能pull下来了,但是git stash apply的时候,报错:
-----------------
$ git.exe stash apply --index stash@{0}
test444444/src/222222222.txt already exists, no checkout
Could not restore untracked files from stash
--------------------
答:这个超级难搞~~~
搜了半天,搜得此文:
http://stackoverflow.com/questions/10508903/cannot-apply-stash-to-working-directory/10508919

解决办法就是:git stash branch STASHBRANCH
把stash开一个分支,然后就能合并了。

=================================================
The best way to do this is to convert the stash to a branch. Once its a branch you can work normally in git using the normal branch-related techniques/tools you know and love. This is actually a useful general technique for working with stashes even when you don't have the listed error. Its works well because a stash really is a commit under the covers (see PS).

Converting a stash to a branch

The following creates a branch based on the HEAD when the stash was created and then applies the stash (it does not commit it).


git stash branch STASHBRANCH


Working with the "stash branch"

What you do next depends on the relationship between the stash and where your target branch (which I will call ORIGINALBRANCH) is now.

Option 1 - Rebase stash branch normally (lots of changes since stash)

If you have done a lot of changes in your ORIGINALBRANCH, then you are probably best treating STASHBRANCH like any local branch. Commit your changes in STASHBRANCH, rebase it on ORIGINALBRANCH, then switch to ORIGINALBRANCH and rebase/merge the STASHBRANCH changes over. If there are conflicts then handle them normally (one of the advantages of this approach is you can see and resolve conflicts).

Option 2 - Reset original branch to match stash (limited changes since stash)

If you just stashed while keeping some staged changes, then committed, and all you want to do is get the additional changes that where not staged when you stashed you can do the following. It will switch back to your original branch and index without changing your working copy. The end result will be your additional stash changes in your working copy.


git symbolic-ref HEAD refs/heads/ORIGINALBRANCH
git reset




Background

Stashes are commits likes branches/tags (not patches)

PS, It tempting to think of a stash as a patch (just like its tempting to think of a commit as a patch), but a stash is actually a commit against the HEAD when it was created. When you apply/pop you are doing something similar to cherry-picking it into your current branch. Keep in mind that branches and tags are really just references to commits, so in many ways stashes, branches, and tags are just different ways of pointing at a commit (and its history).

Sometimes needed even when you haven't made working directory changes

PPS, You may need this technique after just using stash with --patch and/or --include-untracked. Even without changing working directories those options can sometimes create a stash you can't just apply back. I must admit don’t fully understand why. See http://git.661346.n2.nabble.com/stash-refuses-to-pop-td7453780.html for some discussion.

shareimprove this answer
 

评论 COMMENTS
没有评论 No Comments.

添加评论 Add new comment.
昵称 Name:
评论内容 Comment:
验证码(不区分大小写)
Validation Code:
(not case sensitive)
看不清?点这里换一张!(Change it here!)
 
评论由管理员查看后才能显示。the comment will be showed after it is checked by admin.
CopyRight © 心缘地方 2005-2999. All Rights Reserved