2016-08-16 82 views
0

我是新来的Git和尝试很多事情之后发布此。新的git:混帐推给错误

问题很简单:我有一个文件说,在主“A”,它也存在于其他分支说,“测试”。在这两个文件中,有变化,我要合并更改

我知道有很多以前的帖子,哪些社区可以指导我,但我有一个具体的问题,我无法解决:

所以这里有一点事情,我已经试过

  1. 我现在的分支的分支“测试”和本地系统(在git的目录)文件显示从branch.Now我已经合并的变化而变化从主所以我切换到主使用git结帐命令
  2. 然后,使用git拉原产主,也Git的mer ge测试,因为我必须将master从master更改为'test'分支。在努力,这两个命令显示有在文件“A”冲突(如错误的:合并是因为未合并的文件无法自动合并失败等....)
  3. 然后,搜索这些错误,并建议通过我们手动使用像kdiff等一些工具

现在在这里,我的问题上来合并文件职位数:

我可以在Github上(资料库)在主轻松复制现在的变化分支并更新git本地存储库中的文件(它的版本是Branch'test')。我的问题是:git如何知道合并完成?我甚至做到了,并再次运行命令“混帐推起源大师”,但很可以理解的,它没有说,当前分支的末端是背后....等....

我甚至因为我的本地git仓库现在认为已更新和最终更改(手动复制更改后)让我做强制更新使用git push -f origin master(我知道,它不应该是合并此类更改的首选方式)。虽然这个命令运行良好,但是做'git checkout master'会抛出另一个错误,说'文件'需要合并 - 你需要先解析你当前的索引'。

这让我想到,Git不知道合并已经发生并使我知道git如何知道我手动合并了更改?

另一件事pn同样的问题,我知道不知何故,我要比较文件存在本地Git存储库(属于分支测试),其版本存在于主存储库中。 问题:如何将两个文件并排放在本地进行比较?

我知道它应该以某种方式进行,以便GIT也知道合并完成,并在本地机器目前文件已更新,合并后的变化,随时可以推掌握

我知道这可能是一个愚蠢的事情我失踪,但严重无法大量搜索

后发现了什么============================= =================

编辑:添加实际的命令是通过问一些成员..谢谢!

[email protected] MINGW64 /d/GitAll/LearnGit (newGitBranch) 
 
$ git checkout master 
 
Switched to branch 'master' 
 
Your branch is ahead of 'origin/master' by 1 commit. 
 
(use "git push" to publish your local commits) 
 
  
 

 
[email protected] MINGW64 /d/GitAll/LearnGit (master) 
 
$ git pull origin master 
 
remote: Counting objects: 3, done. 
 
remote: Compressing objects: 100% (2/2), done. 
 
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 
 
Unpacking objects: 100% (3/3), done. 
 
From https://github.com/apexkeen/LearnGit 
 
* branch master -> FETCH_HEAD 
 
8682a7a..bed8390 master -> origin/master 
 
Auto-merging Readme.txt 
 
CONFLICT (content): Merge conflict in Readme.txt 
 
Automatic merge failed; fix conflicts and then commit the result. 
 
  
 
[email protected] MINGW64 /d/GitAll/LearnGit (master|MERGING) 
 
$ git merge newGitBranch 
 
error: merge is not possible because you have unmerged files. 
 
hint: Fix them up in the work tree, and then use 'git add/rm <file>' 
 
hint: as appropriate to mark resolution and make a commit. 
 
fatal: Exiting because of an unresolved conflict. 
 
  
 
[email protected] MINGW64 /d/GitAll/LearnGit (master|MERGING) 
 
$ git config --global --edit 
 
  
 

 
  
 
[email protected] MINGW64 /d/GitAll/LearnGit (master|MERGING) 
 
$ git push origin master 
 
To https://github.com/apexkeen/LearnGit.git 
 
! [rejected] master -> master (non-fast-forward) 
 
error: failed to push some refs to 'https://github.com/apexkeen/LearnGit.git' 
 
hint: Updates were rejected because the tip of your current branch is behind 
 
hint: its remote counterpart. Integrate the remote changes (e.g. 
 
hint: 'git pull ...') before pushing again. 
 
hint: See the 'Note about fast-forwards' in 'git push --help' for details. 
 
  
 
[email protected] MINGW64 /d/GitAll/LearnGit (master|MERGING) 
 
$ git push -f origin master 
 
Total 0 (delta 0), reused 0 (delta 0) 
 
To https://github.com/apexkeen/LearnGit.git 
 
+ bed8390...674678e master -> master (forced update) 
 
  
 
[email protected] MINGW64 /d/GitAll/LearnGit (master|MERGING) 
 
$ git checkout master 
 
Readme.txt: needs merge 
 
error: you need to resolve your current index first

+2

你可以给实际的'git'命令行和'git'输出吗? – AnoE

+0

对初学者来说似乎是一个很大障碍的事情之一是,你对情况的分析往往是不正确的。事实上,这通常是你首先陷入混乱的原因。这就是为什么我们坚持看到实际的源代码或命令几乎所有问题,尤其是初学者。 –

回答

1

当git告诉你他们已经发生时,你需要解决冲突。

[email protected] MINGW64 /d/GitAll/LearnGit (master) 
$ git pull origin master 
remote: Counting objects: 3, done. 
remote: Compressing objects: 100% (2/2), done. 
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 
Unpacking objects: 100% (3/3), done. 
From https://github.com/apexkeen/LearnGit 
* branch master -> FETCH_HEAD 
8682a7a..bed8390 master -> origin/master 
Auto-merging Readme.txt 
CONFLICT (content): Merge conflict in Readme.txt 
Automatic merge failed; fix conflicts and then commit the result. 

在这一点上,你需要运行git mergetool修复自述文件中的冲突。一旦你的文件看起来应该如此,你可以运行git commit,它会预先填充提交消息,并提供关于合并和冲突的一些信息。此时,您将可以通过git push更改原点。

就目前而言,你已经尝试去做其他事情,这是开始出问题的地方,因为你必须首先解决冲突(如输出中所述的命令)。

稍后,您已使用git push-f标志,导致远程更改丢失。这是在非学习环境中要避免的!

值得广泛使用git status来查看您的工作副本在任何给定时间发生了什么。

+0

啊。我错过的重要的事情是。合并后,我忘了做混帐提交..这是创造各种问题。虽然我还没有回答什么问题,但仍然会标记这个答案..谢谢! –

1
  1. 提交测试的代码分支。
  2. 签出并掌握并做git pull origin master,确保你的master是最新版本库。
  3. 结帐测试分支并进行重新分配。
  4. git rebase master,如果它完成没有任何冲突比你好,否则手动解决特定文件中的冲突。
  5. 解决冲突后做git rebase - 继续
  6. 之后做git add。 & git commit。
  7. 现在你已经全部设置好了,你将拥有来自主分支和测试分支的所有更改。
+0

第6位发生在哪里?当你重新绑定时,不需要提交? – rubenvb

+0

当所有的冲突都得到解决 –

+0

然后你通常会做git add。和git rebase - 继续。没有必要或想要在该流程中的任何git提交,在任何地方... – rubenvb