2

We have to add new features to a preexisting project. So everyone creates their own branch to make a feature.

now after i added some code to my specific branch my teammates told me its best to rebase to make future merges easier.

Now because we are at the very begining of starting the project a lot of small files have been changed, like the pom.xml file, the .gitlab-ci.yml file, giving me lots of merge errors. Also while i have been trying to get a mental grip on this whole github thing my teammates have added some more code in the meantime and i cant see the forest trough the trees anymore.

so what i am trying to do is keep my new code but update my specific branch with all the code from the main branch.

if i am not mistaken this is exactly what a rebase does right?

while i executed a rebase like so :

-git rebase master

it gave me 20 merge errors. But the fact is that it goes trough every update made since the start of my branch when it first forked, and a lot of the times its just the same file being rewritten. so what i did was just copy paste the file from the github into my project (its only a few files) and then carefully read every merge error and if it originated in the files i copy pasted, i just skipped them.

(what also was weird was that some of the files kept getting errors even tough i just copy pasted the exact file from the branch i am rebasing to)

then when i finnaly get past the last error it gives me this

fatal: update_ref failed for ref 'refs/heads/dev_504': 
cannot lock ref     'refs/heads/dev_504': ref refs/heads/dev_504 is at
XXXXXXX 
but expected     XXXXXXXX
Could not move back to refs/heads/dev_504

then i restart the computer and get this

fatal: cannot resume: .git/rebase-apply/final-commit does not exist.

then i abort the rebase and when i try again, i get 20 errors again.

github is so complicated , all i want to do is get the code from the main branch and add mine to it(which is only 1 file by the way).

so alternatively could i just force pull from main branch and then just add my file? i feel like its not how ur suposed to do it.

P.S. : i added a library trough maven, does this influence pull and push in any way?

Thanks

jelte
  • 57
  • 1
  • 9
  • If you want to make it easier, you could start by rebasing interactively all your commit on the initial master (i.e. on the commit where you started your branch), and squash all the commits into a single one. Then rebase that single commit on master. You'll still have conflicts, but you'll have to resolve them only once. – JB Nizet Oct 30 '16 at 17:20
  • Does this answer your question? [Git rebase failing](https://stackoverflow.com/questions/34695044/git-rebase-failing) – Inigo Dec 06 '21 at 23:46

1 Answers1

0

What you could do is to compress/squash all commits on your branch into one consolidated commit. To do so you have to find common ancestor for master and feature_branch. The command git merge-base --all master feature_branch will give the hash(es) of best common ancestor(s) (it's better if there is only one hash). Remember that hash (X). Now you need to represent your work as a single commit. You can do interactive rebase or reset shortcut(git reset --soft, git commit). I personally prefer latter. Make sure you are in your feature branch and have clean status.

git reset --soft X
git commit -m'MESSAGE'
git rebase master <= sort conflicts
git checkout master
git merge feature_branch <=it will be FastForward merge
IrLED
  • 438
  • 2
  • 5