Git:从分支推送导致不需要的文件被提交

时间:2022-09-10 16:26:03

I am stuck with a weird problem which i dont seem to understand. I had two local git branches which both pointed to the same remote. Local branches are master and tenant and i have the following config in .git of my ws

我遇到了一个我似乎不明白的奇怪问题。我有两个本地git分支,它们都指向同一个遥控器。本地分支机构是主人和租户,我在我的ws .git中有以下配置

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = git@egitrepo:project.git
[branch "master"]
    remote = origin
    merge = refs/heads/master
[branch "tenant"]
    remote = origin
    merge = refs/heads/master

I did this so i can do git pull easily on both the branches without specifying the remote on the command line.

我这样做了所以我可以轻松地在两个分支上执行git pull而无需在命令行上指定远程。

I am working on the tenant branch while my master branch was not updated and old. I made changes in my tenant branch, did git pull and tried to push the changes to remote.

我在租户分支机构工作,而我的主分支机构没有更新和旧。我在我的租户分支中做了更改,做了git pull并尝试将更改推送到远程。

Doing git push from the tenant branch gave me the fast-forward error.

从租户分支执行git push给了我快进错误。

To git@egitrepo:milkyway.git
    ! [rejected]        master -> master (non-fast-forward)
  error: failed to push some refs to 'git@egitrepo:milkyway.git'

At this point, i looked around and found that this was due to git push trying to push all my local branches to the remote i.e both my tenant and master(non-updated).

此时,我环顾四周,发现这是由于git push试图将我所有的本地分支推送到遥控器,即我的租户和主人(未更新)。

I found a solution to this problem by setting

我通过设置找到了解决这个问题的方法

 git config --global push.default upstream

which tells git to push only the current branch to its matching upsteam branch. This solved my problem and my push from tenant branch went successful.

它告诉git只将当前分支推送到其匹配的upsteam分支。这解决了我的问题,我从租户分支的推动成功了。

Now comes the problem part, when i looked at the commit history by using git diff to see my commit, i found a number of other files which SHOULD NOT have been a part of the commit. I had added only 8 files for commit and looked at git status very carefully before doing the commit and it showed only the 8 correct files under the changes to be commited section.

问题部分来了,当我通过使用git diff查看我的提交查看提交历史时,我发现了许多其他文件,它们不应该是提交的一部分。我只提交了8个提交文件,并且在提交之前非常仔细地查看了git状态,它只显示了要提交的更改下的8个正确文件。

How did all those other files went into my commit? Were they added from the master as part of the first failed git push i tried? I say this because these are some of the files i changed in the master branch. Why did git not show them to me in the correct section of git status.Can anybody explain this? Also how can i revert?

所有其他文件是如何进入我的提交的?作为第一次失败的git推送的一部分,他们是否从主人那里加入了我试过的?我这样说是因为这些是我在master分支中更改的一些文件。为什么git没有在git status的正确部分向我显示。可以解释一下吗?另外我怎么回复?

1 个解决方案

#1


1  

You can review the commit history and reflog to determine what happend.

您可以查看提交历史记录和reflog以确定发生的情况。

Use git-reflog and I bet you will see a merge from master to tenant.

使用git-reflog,我打赌你会看到从主人到租户的合并。

#1


1  

You can review the commit history and reflog to determine what happend.

您可以查看提交历史记录和reflog以确定发生的情况。

Use git-reflog and I bet you will see a merge from master to tenant.

使用git-reflog,我打赌你会看到从主人到租户的合并。