0

update1:

right now I am facing conflicts when I do rebase. after I modify the code. Can you let me know what command to execute to remove the conflicts. Providing the status below

sports/code/file (branchB)
$ git pull --rebase origin branchA
From https://gitlab.sports.com
 * branch            branchA -> FETCH_HEAD
First, rewinding head to replay your work on top of it...
Applying: wip html fixes
Using index info to reconstruct a base tree...
M       sports/ajax.js
Falling back to patching base and 3-way merge...
Auto-merging sports/ajax.js
CONFLICT (content): Merge conflict in sports/ajax.js
error: Failed to merge in the changes.
Patch failed at 0001 wip html fixes
The copy of the patch that failed is found in: .git/rebase-apply/patch

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".



sports/code/file (branchB|REBASE 1/2)
$ git status
rebase in progress; onto 89898989892323
You are currently rebasing branch 'branchB' on '89898989892323'.
  (fix conflicts and then run "git rebase --continue")
  (use "git rebase --skip" to skip this patch)
  (use "git rebase --abort" to check out the original branch)

Unmerged paths:
  (use "git reset HEAD <file>..." to unstage)
  (use "git add <file>..." to mark resolution)

        both modified:   sports/ajax.js

no changes added to commit (use "git add" and/or "git commit -a")
  • I am trying to learn rebase.
  • I have a branch A which is created from develop branch,
  • from the branch A I created a new local branch B.
  • i did a git rebase using this command git pull --rebase origin A
  • no if I do git push -f origin B will my code go into branch B alone or will it go into branch A also.
  • if I type git status in branch B I am seeing the below message.
  • i followed this medium link https://medium.com/@gitaumoses4/git-rebase-a-tool-for-excellent-git-workflow-3aaa1bba40a4
  • can you tell me how to fix it, so that in future I can do it myself
$ git status
On branch B
Your branch and 'origin/B' have diverged,
and have 7 and 1 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)
nothing to commit, working directory clean

1 Answers1

0

From the branch A I created a new local branch B.

a--a--a (A)
       \
        b (B, origin/B, meaning this is the initial commit pushed to the remote repo)

Now, if I do git push -f origin B, will my code go into branch B alone or will it go into branch A also.

Branch B alone, but that branch B will include branch A commit.

That is because, when you did:

git checkout B
git pull --rebase origin A

You went from

a--a--a--a--a--a (A)
       \
        b--B--B--B--B--B (local work B)
        ^
    (origin/B)

To:

              (A)
               v
a--a--a--a--a--a--b'--B'--B'--B'--B'--B' (new rebased B work, on top of A)
       \
        b
    (still origin/B)

That is why you see:

Your branch and 'origin/B' have diverged,
and have 7 and 1 different commits each, respectively.

In your case, if git status shows you that you are working with B, you can do

git push --force

You will then get:

a--a--a--a--a--a--b'--B'--B'--B'--B'--B' (B, origin/B)

Your branch B now includes commits from A, but branch A remains unchanged.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • hey I have one more question, instead of `git push -f origin` why are you doing `git push --force`, in my command why they are mentioning origin. I thought origin means initial branch and it will got branch A :( –  May 18 '19 at 11:44
  • @zizi "origin" doe snot mean "initial branch": it only means *where* to push (the URL of the remote repo). It is the default one used, so `git push --force` is the same as `git push -f origin` – VonC May 18 '19 at 13:08
  • @zizi If you have checked out branch B before forcing the push, *what* is push will be branch B only, because of the default push policy (https://stackoverflow.com/a/948397/6309) – VonC May 18 '19 at 13:11
  • hey I did seven different commits in my branch B, is it possible to combine all my commits into one since I have done rebase will It be problem, can you tell me how to achieve it –  May 20 '19 at 20:13
  • @zizi After a rebase, you still can squash your last n commits together: https://stackoverflow.com/a/5201642/6309 – VonC May 20 '19 at 21:13
  • hey do I need to excute this two commands `git reset --soft HEAD~3 && git commit - m 'combine all ` –  May 21 '19 at 13:17
  • 1
    @zizi Yes, but only after the rebase, and only if the last 3 commits are the one you want to squash into one. – VonC May 21 '19 at 13:22
  • thanks, can you help me with this one too https://stackoverflow.com/questions/56226829/how-do-i-change-the-layout-for-smaller-screens-in-material-ui –  May 21 '19 at 13:53
  • @zizi Sure, I have posted my answer. – VonC May 21 '19 at 16:08
  • hey after executing this commands `git reset --soft HEAD~3 && git commit - m 'combine all` is it possible to merge code from branch B to branch A using git commands –  May 22 '19 at 19:06
  • @zizi Yes, with `git checkout A` and `git merge B` – VonC May 23 '19 at 04:32
  • @zizi To *merge* code from branch A to branch B? That is what [`git merge`](https://git-scm.com/docs/git-merge) is made for. Do you have any issue with it? – VonC May 23 '19 at 13:20
  • @zizi That would be different, and would replay commits from A on top of B: https://www.atlassian.com/git/tutorials/merging-vs-rebasing In your case, this is not recommended. – VonC May 23 '19 at 13:23
  • hey now I am facing conflicts, can you help me in fixing the conflicts :( –  May 23 '19 at 19:57
  • @zizi Could you make that new updated case as a separate and new question? My answer was in the context of your original question. – VonC May 23 '19 at 21:58
  • hey can you help me https://stackoverflow.com/questions/56297314/rebase-conflict-issue-in-branch-b –  May 24 '19 at 17:41