git-git fetch/git merge合并时没有冲突,但是显示几乎所有文件都已修改并且需要提交 [英] git - A git fetch / git merge merges without conflicts, but shows almost all files are modified and need to be committed

查看:910
本文介绍了git-git fetch/git merge合并时没有冲突,但是显示几乎所有文件都已修改并且需要提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是git的新手,而且我偶尔也会看到它.

I am very new to git and I have been seeing this every once in a while.

例如:

  1. 我在分支机构branch-A工作了几天(分支是通过开发新副本创建的)
  2. 我执行git add . / git commit -m "blahblah"来暂存并提交我的更改
  3. 现在我想从远程获取最新更改并将其合并到我的分支中,以确保可以使用最新代码
  4. 这样做,我执行git checkout develop切换到我的本地develop分支,git status显示我落后37次提交

  1. I work on my branch branch-A for few days (branch is created from develop fresh copy)
  2. I do git add . / git commit -m "blahblah" to stage and commit my changes
  3. Now I want to get latest changes from remote and merge it into my branch so I ensure I work on latest code
  4. to do so, I do git checkout develop to switch to my local develop branch, git status shows I'm behind 37 commits

myMBPro:MyProj$ git status
On branch develop
Your branch is behind 'origin/develop' by 37 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

,然后是删除的,未跟踪的文件列表

and the list of deleted, untracked files follow

git fetch origin,然后在develop分支上显示git merge origin/develop:

git fetch origin, then git merge origin/develop while on develop branch shows:

myMBPro:MyProj user$ git fetch origin myMBPro:MyProj user$ git merge origin/develop Updating 799c6d7a..510c77ab Fast-forward .../Implementations/MyRenderer.cs | 39 ++-- ... etc

myMBPro:MyProj user$ git fetch origin myMBPro:MyProj user$ git merge origin/develop Updating 799c6d7a..510c77ab Fast-forward .../Implementations/MyRenderer.cs | 39 ++-- ... etc

  1. 我现在通常会切换到我的分支branch-A并执行git merge develop以将开发合并到branch-A,但是通常我首先执行git status来检查一切是否正常.因此,我留在develop分支上并执行git status
  2. 问题是我看到git status报告的项目中的每个文件可能都已更改(有的未跟踪,有的已分阶段,有的已准备好提交).
  1. I would typically now switch to my branch branch-A and do git merge develop to merge develop to branch-A but I typically do first git status to check all is OK. So, I stay on develop branch and do git status
  2. The problem is that I see git status reporting probably every single file in my project as changed (some as untracked, some as staged and some as ready to be committed).

```

myMBPro:MyProj user$ git status
On branch develop
Your branch is up to date with 'origin/develop'.

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

,以及准备提交的文件,未暂存的文件和未跟踪的文件的列表.

, and the list of files ready to commit, files not staged, and files that are untracked follows after this.

因此,我最终得到了很多文件,这些文件甚至都没有被我触及,修改或添加,现在显示为我以某种方式进行了修改.结果,我不愿意将它们合并到我的branch-A中.

So, I end up with lots of files that I haven't even touched, nor modified, nor added now showing as being somehow modified by me. As a result, I am hesitant to merge them in my branch-A.

有人知道为什么会这样吗?甚至正常吗(但对我来说,未更改的文件在我更改文件时听起来并不正常,现在我需要开始跟踪它们,暂存并提交它们.

Any idea why is this happening? Is it even normal (but to me it does not sound normal that files I have not changed appear as they are changed by me and now I need to start tracking them, stage and commit them.

我在MacBookPro上,使用终端中的git并使用SourceTree

I am on MacBookPro, using git from terminal and also using SourceTree

推荐答案

确定要在git checkout develop之前执行git commit吗?如果您的工作目录在checkout developpull之前是脏的,那么我知道发生这种情况的唯一方法.

Are you sure that you did git commit immediately before git checkout develop? The only way that I know this can happen if your working directory is dirty before you checkout develop and pull.

当然,可能存在行尾问题,但这仍然不能真正解释问题. git merge的一个重要方面是必须提交.如果没有冲突,则可以保证提交,并且只有合并冲突时,它才不会提交(这会使您处于各种暂存和未暂存文件的状态).如果您没有合并冲突(意思是看到单词fast-forward),那么似乎只有一种可能性:

Sure, there might be line ending problems, but this still doesn't really explain the issue. An important aspect of git merge is that it must commit. It is guaranteed to commit if there are no conflicts, and the only way it wont commit is if there are merge conflicts (Which can leave you in that state of variously staged and unstaged files). If you aren't getting merge conflicts (Meaning you see the words fast-forward), then there seems to be only one possibility:

假设您正在分支A上工作.然后提交.然后,您更改了几个文件(或者,同时运行的某些软件会自动更改它们).然后,当您git checkout develop时,您最终将复制index. index是自最近一次提交以来所做的所有更改的集合.您可以签出另一个分支,索引将跟随您.据我所知,这似乎是唯一可能导致您遇到的问题的东西.如果合并影响文件中索引的那一部分,则合并将失败.但是,如果一个简单的fast-forward错过了您的index,合并可能会成功,这将导致您的index显示在最新提交的顶部.

Say you're working on branch A. Then you commit. Then, you change a couple of files (Or, they are changed automatically by some software you have running at the same time). Then, when you git checkout develop, you end up copying your index. The index being the set of all of the changes you've made since the most recent commit. You can checkout another branch and your index will follow you. This seems to be the only thing, as far as I'm aware, that could cause what you're experiencing. If the merge affects files that part of your index, then the merge will fail. However, it's possible for the merge to succeed if it's a simple fast-forward that misses your index, which will cause your index to be shown on top of the most recent commit.

为了将来,请尝试在git fetch origin; git merge origin/develop之前运行git status.如果仍然遇到麻烦,则可能必须复制粘贴终端中的内容,以便我们阅读.

For the future, try running git status before git fetch origin; git merge origin/develop. If you're still running into trouble, you might have to copy-paste what's in your terminal so we can read it.

此外,请确保在回购中仅包含源代码和构建脚本,并.gitignore将任何可能由vim,您的IDE,您的构建脚本,正在运行的可执行文件等创建的文件.这些文件可能会不断变化.

Also, make sure to only have source code and build scripts in the repo, and to .gitignore any files that might be created by vim, your IDE, your build scripts, the running executable, etc. Any of those files are likely going to change constantly.

这篇关于git-git fetch/git merge合并时没有冲突,但是显示几乎所有文件都已修改并且需要提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆