Git rebase

I need help.
firs I commit project and then I pull from origin and get this issue and whole new change files in my repo

I think this happened because my project is back then origin and my new commit must take correct order
then i try git rebase -i and get another issue.
what can i do? I don’t want to destroy something
I want my last commit set top of the project and other commit would not be destroyed.

now my repo look like:

So you don’t want to lose any of the commits on origin/master as well?

Yes Daniel.
why its happened, first I commit and then pull the project as it is recommended

Well rebasing changes the history so you’ve diverged.

You’re apparently in the middle of a rebase so I’m not quite sure if you wanted to go through with that you need to continue or abort it.

As you’re also a detached HEAD you would also need create a branch and possibly commit or stash your changes.

From there I would create a temporary branch and merge both to hopefully get it a state you’re happy with.

I don’t know what git did rebase or merge but he fix the issue, but meanwhile someone update origin repo again and now I have same result

now I see that my branch and origin is different.
how can I do so that I commit my changes and back into origin branch and don’t destroy destroy other commits?

Well that’s expected if you’re working with people. You’d stash your changes, pull, apply the stash and fix any merge conflicts.

Ideally no one should be pushing to master directly. You’d each have your own branch to push to and then have pull requests to merge your stuff into master.

if I stash my changes and then pull do I have conflict ?
and if I have not conflict how merge commits in such way that files which is not changed by me will be overwritten by origin master and files which I changed stay invariably ?

That depends entirely on the changes that were made. You’ve made 2 commits since origin/master and it’s made 1, so if you’ve both modified the same pieces of code you would have a merge conflict.

I’m not quite sure what you’re asking here.

how can I merge thus, can you help me?

it’s something crazy. i have tried to fix it last two days

Well I don’t use source tree but I would assume you can just right click the origin/master commit you want to merge.

You’ll probably get merge conflicts which you would need to resolve before committing the merge.

how can I merge thus, can you help me?
it’s something crazy. i have tried to fix it last two days

One of the ways to merge it would be to create new branch where your origin/master on the screenshot is: double click on the commit at which origin/master is at and switch to that commit. Then press on the Branch button at the top to create new branch, give it a name such as mergingBranch. Then double click on your master branch in the BRANCHES section. Now right click on the mergingBranch on the left there and choose merge mergingBranch into current branch.

It will create a merge commit since it can’t fast-forward the origin/master to your master. After that you can push your changes to your origin/master and continue working.

If you don’t want to merge and want linear history without merge commits no matter what, you can use git rebase --onto origin/master d1403431 master. This command will reapply commits after d1403431(not including the d1403431 commit, but including all after it) and master commit(including the commit at master) onto the origin/master commit.

This will result in a linear history and you can just push your changes on your current master commit to origin/master without merging it first or losing work.

You’ll have to use the command line tool. I haven’t seen this functionality in Sourcetree. There’s rebase feature in Sourcetree, but without the --onto parameter.

git rebase and git rebase --onto are very useful features and I recommend you to familiarize yourself with how they work before you use it:

You also want to git gud at git. The first link is a part of the book:

Git is very unintuitive without understanding exactly how it works. I recommend to read chapters 1, 2, 3, 6, 7 in the book to nicely understand how it works. You don’t need other chapters: server configuration and how it works behind the scene.

It’s a very-very easy read(the Pro Git book) compared to the UE4 course on this website or C++ books like These parts are only 150 pages and it should take 1-3 days of reading.

1 Like

Thank you very much, I have solved it.
it is first time I work in team and it is really different when you work alone

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.