我是GIT的新手并在尝试了很多事情之后将其发布。
问题很简单:我有一个文件说' A'在主人,这也存在于其他分支说'测试'。在这两个文件中,都有变化,我将合并更改
我知道有很多早期的帖子,社区可以指导我,但我有一个我无法解决的具体问题:
所以这是我尝试过的事情
现在我的问题出现了:
我可以轻松复制主分支中Github(存储库)中存在的更改,并在git本地存储库中更新该文件(其版本为Branch' test')。我的问题是:git如何知道合并完成了?我甚至做了那个并再次运行命令git push origin master'但可以理解的是,它失败了,当前分支的提示落后......等等......
我甚至认为,因为我的本地git存储库现在已更新并且最终更改(手动复制更改后)让我使用git push -f origin master强制更新(我知道,它不应该是首选的合并方式这样的变化)。虽然这个命令运行正常但是做了git checkout master'抛出另一个错误说文件' A'需要合并 - 您需要先解决当前的索引。
这让我觉得Git不知道合并已经发生了,并且让我知道git如何知道我手动合并了变化???
同样问题的另一件事,我知道,我已经将本地Git存储库(属于分支测试)中的文件A与存储库中的master中存在的版本进行比较。 问题:如何在本地将两个文件并排进行比较?
我知道它应该以某种方式完成,以便GIT也知道合并完成并且本地机器中存在的文件已更新合并的更改并准备推送到主
我知道这可能是我失踪的傻事之一,但经过大量搜索后却发现无法找到任何东西
============================================== < / p>
编辑:按照少数成员的要求添加实际命令..谢谢!
2000@LTDLUK3400 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)
2000@LTDLUK3400 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.
2000@LTDLUK3400 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.
2000@LTDLUK3400 MINGW64 /d/GitAll/LearnGit (master|MERGING)
$ git config --global --edit
2000@LTDLUK3400 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.
2000@LTDLUK3400 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)
2000@LTDLUK3400 MINGW64 /d/GitAll/LearnGit (master|MERGING)
$ git checkout master
Readme.txt: needs merge
error: you need to resolve your current index first
&#13;
答案 0 :(得分:1)
答案 1 :(得分:1)
当git告诉你他们已经发生时,你需要解决冲突。
2000@LTDLUK3400 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
来查看您在任何特定时间内工作副本的情况。