Skip to main content



      Home
Home » Eclipse Projects » EGit / JGit » Strange EGit Staging(Branches Ahead/Behind)
Strange EGit Staging [message #1860046] Thu, 13 July 2023 14:10 Go to next message
Eclipse UserFriend
Fig 1 shows History after merging feature-01 into main then doing another commit to main (d6de49a). Staging now says main is 4 commits ahead of the remote. Are these 4 commits the 2 prior commits to feature-01 (6165b05, e82d203) plus the merge commit (b99e2c8) plus the "Update #3" commit (d6de49a)? Please explain.

Prior to pushing main, staging of the feature-01 branch is not ahead or behind. In Fig 2 I pushed the main branch so it no longer has any staged changes but the local feature-01 branch now shows it's 4 commits behind the remote. Why? The feature-01 branch is still only on the local repo (never pushed to the remote). Which 4 commits to the feature-01 branch is staging referring?

I may have forgotten some steps so I also show the Reflog.
index.php/fa/43330/0/
Re: Strange EGit Staging [message #1860048 is a reply to message #1860046] Thu, 13 July 2023 14:35 Go to previous messageGo to next message
Eclipse UserFriend
I wonder how origin/main ever got to commit e82d. I guess you did push feature-01 after all, and origin/main is the remote tracking branch of feature-01.

The four commits that main is initially ahead of origin/main are (from bottom to top) caa2, 798e, b99e, and d6de. (All commits from main to the merge base between main and origin/main, which is 637f.) origin/main is the same commit as feature-01.

Then you push main, which updates origin/main to that same commit. So evidently now origin/main is the same four commits ahead of feature-01, and thus feature-01 is these four commits behind its remote tracking branch, which is origin/main.
Re: Strange EGit Staging [message #1860175 is a reply to message #1860048] Thu, 20 July 2023 13:47 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for clarifying how main is now 4 commits ahead - it now makes sense!

While I was playing with Merge, I just now remembered I also played around with "Push commit..." (to force staging). This could explain how origin/main ended up at commit e82d in Fig 1 without my pushing the feature-01 branch. The 4 steps below and in Fig 3 are probably what I did:


  1. Select the commit you want to be the head of one of the branches on the remote. In this case I selected commit e82d. Right-click that commit and select "Push Commit..."
  2. In that dialog box, enter "main" and check "Force overwrite" then press "Push".
  3. It shows the Push Results.
  4. EGit history now shows origin/main at that commit (which just happened to also be the head of local feature-01 branch).


EGit history now shows origin/main at that commit (which just happened to also be the head of local feature-01 branch).

So, commit e82d, not the feature-01 branch, was pushed to main on the remote. Staging of main is recalculated based on the new origin/main. In this case the local main is now 4 commits ahead and without a feature-01 branch on the remote.

Does that make sense? "Push commit..." doesn't alter the local repo so the Reflog doesn't show that activity. I doubt you can push any commit to any branch in that remote so please explain.
index.php/fa/43342/0/
Re: Strange EGit Staging [message #1860177 is a reply to message #1860175] Thu, 20 July 2023 15:22 Go to previous messageGo to next message
Eclipse UserFriend
Ray Martin wrote on Thu, 20 July 2023 17:47
so please explain.


Errr -- explain what exactly?

I see that "Push Commit..." did actually use the "push branch" dialog since it detected that feature-01 was pointing to that commit. And the dialog (fig 3b) has "Configure upstream for push and pull" checked, so the remote tracking branch of feature-01 will be set to "origin/main".

Perhaps the menu label could be changed to "Push Branch..." when the command is going to use the "Push Branch" dialog. Might that be helpful?
Re: Strange EGit Staging [message #1860391 is a reply to message #1860177] Wed, 02 August 2023 17:16 Go to previous messageGo to next message
Eclipse UserFriend
The explanation I'm seeking is why would you want to use "Push Commit..." to a different branch? I do see the value of pushing to a prior commit on that same branch. I've used this to remove commits from the tip of that remote branch or to force staging so the local branch is ahead.

My novice EGit brain can't comprehend all that happens when you push a local commit to a different branch or why you would want to do that. An example would help. Won't this create conflicts and set staging that's ahead AND behind? Does this relate to "Cherry pick"?
Re: Strange EGit Staging [message #1860402 is a reply to message #1860391] Thu, 03 August 2023 04:50 Go to previous messageGo to next message
Eclipse UserFriend
Staging has nothing to with whether the local branch is ahead or behind the remote tracking branch. A change that is staged is recorded in the git index, and will be included in the next commit you make.

Pushing a commit to several remote branches might make sense if you want to bring different remote branches to the same commit. Branches in git are just named pointers to a commit.

So assuming you have (oldest commit on the left, newest on the right)
    Local clone                                         Upstream repo

    origin/foo            main                          foo
    |                     |                             |
    v                     v                             v
  --o---------------------o                           --o
    8a462d0               c379326                       8a462d0
    ^                                                   ^
    |                                                   |
    origin/main                                         main

and you "push to main" you'll end up with
    Local clone                                         Upstream repo

    origin/foo            main                          foo
    |                     |                             |
    v                     v                             v
  --o---------------------o                           --o---------------------o
    8a462d0               c379326                       8a462d0               c379326
                          ^                                                   ^
                          |                                                   |
                          origin/main                                         main

The commit is pushed, the upstream's main branch is updated to point to that commit, and origin/main (the local copy of that upstream branch) is also updated.

If you then push the same commit again to foo, no new commit will be pushed (since it already was pushed), but foo and origin/foo (the local copy of the upstream's foo branch) will also be updated to point to that commit.
    Local clone                                         Upstream repo

                          origin/foo
                          |main                                               foo
                          ||                                                  |
                          vv                                                  v
  --o---------------------o                           --o---------------------o
    8a462d0               c379326                       8a462d0               c379326
                          ^                                                   ^
                          |                                                   |
                          origin/main                                         main

Re: Strange EGit Staging [message #1860739 is a reply to message #1860402] Wed, 30 August 2023 14:36 Go to previous message
Eclipse UserFriend
When I earlier mentioned "force staging" or "set staging that's ahead AND behind", that related to the way EGit's "Git Staging" view shows the Ahead/Behind counts. The top section in the latest image below is an example.

To make it easier for me, I translated your text diagrams into EGit format using the same commit IDs. Please verify/correct my diagrams shown in the Step 1-3 blue boxes.
index.php/fa/43452/0/
Previous Topic:Why does the New Branch dialog sometimes use the same name as the remote, and sometimes not?
Next Topic:Using UltraCompare as external compare tool
Goto Forum:
  


Current Time: Tue May 20 02:59:04 EDT 2025

Powered by FUDForum. Page generated in 0.10405 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top