Git stash pop自动合并完成以下

时间:2017-12-04 19:29:57

标签: git git-bash

我正在尝试恢复未保存的文件(藏匿文件)

我不得不做一个小代码更改,因为我的遥控器是一个提交1个文件更改的头( file1 )。我需要先使用远程更新我的本地并推送我的更改,因为我必须在本地存储我的更改,因为我在本地修改了相同的文件( file1 )。所以我做了以下几点。

$git stash
  Saved working directory and index state WIP on dev: 4eb5499

$git pull
  Updating 4eb5499..db82e7c
  Fast-forward

$git add file2 //this is different file.
$git commit
$git push

//with this done on my dev branch I also want to update my master branch with remote

So

$git checkout master
  Switched to branch 'master'
  Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.

$git pull 
  Updating 4eb5499..db82e7c
  Fast-forward

$git merge dev //to update my changes on master
$git push

  with this done my remote is updated with my changes. both on dev/master branch.

  Now I have switched my branch again. 

$git checkout dev
$git stash pop
  Auto-merging **file1**
  CONFLICT (content): Merge conflict in **file1**

  As i have done
$git status

  On branch dev
  Your branch is up-to-date with 'origin/dev'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

   So I have performed the following
$ git reset HEAD

$ git status
  On branch dev
  Your branch is up-to-date with 'origin/dev'.

  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)

$ git stash list
  stash@{0}: WIP on dev: 4eb5499 //I want the changes which are here.
  stash@{1}: WIP on master: 9dac6b5

$ git stash pop
  error: Your local changes to the following files would be overwritten by merge:

我只想让我的藏匿文件再次使用。

2 个答案:

答案 0 :(得分:0)

我发现git在文件上添加了几行,看起来文件中存在一些错误(通过编译器),所以进入文件并删除git添加的行

<<<<<<< Updated upstream

between this
code may be replicated again please check and delete.

=======
>>>>>>> Stashed changes

答案 1 :(得分:0)

这是因为您尝试通过"primeng": "^4.3.0"应用的存储提交与当前工作树冲突。

许多人错误地认为git stash pop没有提交,因此运行git stash而不是git commit。事实并非如此:事实上,git stash使至少提交了两次提交。 (根据您给出的标志git stash,它可能会进行三次提交而不是两次。)git stash提交的提交最特别的是它们 on no branch在所有

尽管如此,它们仍然是提交,就像其他提交一样。当你去“弹出”一个藏匿处时,这只是意味着git stash。也就是说,你告诉Git git stash apply && git stash drop存储你当前的工作树内容。如果Git认为这很好,那么你告诉Git apply存储,即丢弃存储提交。

在某些情况下,隐藏提交不会干净利落,您将遇到合并冲突,就像您运行dropgit merge时一样。您必须解决此合并冲突,就像处理任何其他合并冲突一样。请注意,在这种情况下,Git 删除了存储:git cherry-pick仍然会显示它。

有关解决存储冲突的更多信息,请参阅How to resolve git stash conflict without commit?