来自当前分支之前的分支的git checkout文件

时间:2014-10-15 11:23:13

标签: git

我创建了一个本地git仓库,其中包含2个分支,masterstable
使用master作为开发分支,它在stable之前提交了4-5次提交,并且还包含一些非暂存编辑。

问题在于stable出现了一个错误,因此我在master上隐藏了我的非暂停编辑内容并对stable执行了结帐。 现在我需要一个来自master的文件,特别是travis.yml,所以我可以将它添加到stable,以便我提交错误修复。

是否有一种干净的方法可以将stable合并回master时与现有的travis.yml没有冲突?

这是我尝试过的但没有运气..

rob@laptop:~/git/project$ git status
On branch stable
Your branch is up-to-date with 'origin/stable'.

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:   config/user.properties

no changes added to commit (use "git add" and/or "git commit -a")

rob@laptop:~/git/project$ git checkout master/86e6e26acf .travis.yml
error: pathspec 'master/86e6e26acf' did not match any file(s) known to git.
error: pathspec '.travis.yml' did not match any file(s) known to git.

2 个答案:

答案 0 :(得分:0)

所以在修复bug之后,你期待&#34; travis.yml&#34;跨大师和稳定相同?在这种情况下,简单的方法是结帐主人,将travis.yaml的内容复制到临时位置,结账稳定替换travis.yaml in stable与你保存的那个。

Git足够聪明,可以识别两个文件是否相同,而不是显示任何合并冲突。实际上,git只为两个分支存储一个文件。我希望这会有所帮助。

答案 1 :(得分:0)

@ R0MANARMY答案对我有用..

&#34;错误似乎非常自我解释,pathspec master/...不存在。我非常确定您要查找的命令是git checkout master -- .travis.yml。这里有一个相关问题:Meaning of Git checkout double dashes.&#34;