auny
auny

Reputation: 1970

Git:push from branch caused unwanted files to be committed

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

[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.

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.

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

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).

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.

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.

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?

Upvotes: 2

Views: 285

Answers (1)

Michael
Michael

Reputation: 10474

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

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

Upvotes: 1

Related Questions