admin管理员组

文章数量:1319477

I have a feature branch 23-fft-channelizer and a main branch. 23-fft-channelizer is way ahead of main and main has either had no commits or maybe just the readme in the life of 23-fft-channelizer.

I now want to rebase 23-fft-channelizer on to main and basically want 23-fft-channelizer to overwrite what's in main since it 23-fft-channelizer is the most up to date and working branch.

I would however want to keep the history of main in case I ever need to refer back to it.

REMOTE REPO

.py

ENVIROMENT

I am using VSCode for my IDE and on a Windows OS.

STEPS SO FAR

  1. Made a backup copy of branch 23-fft-channelizer in case anything goes wrong.
  2. Sync'd both main and 23-fft-channelizer with remote repo. (git pull on each main/feature - response was up to date on both)
  3. Made sure both are saved to local disk.
  4. git rebase main

Now this is where the issues start. I get a conflict with the option to resolve in the VSCode IDE about which code to accept. It looks like this:

255: <<<<<<< HEAD
256:        samples = signal.convolve(samples, [1]*189, 'same')/189
257:       
258:        #for testing - log to file
259:        #self.f.write(samples.astype(np.float32).tobytes())
260:        
261:=======
262:        samples = signal.convolve(samples, [1] * 10, "same") / 189
263:
264:        # for testing - log to file
265:        # self.f.write(samples.astype(np.float32).tobytes())
266:
267:>>>>>>> 1f893dc (Make project runnable on Linux)

ISSUE

Neither of those lines can I find in the current local copy of that file, but it does exist on the repo at .py#L240

Q: So what is going on - why is that line not on my local copy and how can I resolve this?

Q: Are the two code snippets above diff's between two versions of main ?

I have a feature branch 23-fft-channelizer and a main branch. 23-fft-channelizer is way ahead of main and main has either had no commits or maybe just the readme in the life of 23-fft-channelizer.

I now want to rebase 23-fft-channelizer on to main and basically want 23-fft-channelizer to overwrite what's in main since it 23-fft-channelizer is the most up to date and working branch.

I would however want to keep the history of main in case I ever need to refer back to it.

REMOTE REPO

https://github/bigalnz/test_fft/blob/main/src/kiwitracker/sample_processor.py

ENVIROMENT

I am using VSCode for my IDE and on a Windows OS.

STEPS SO FAR

  1. Made a backup copy of branch 23-fft-channelizer in case anything goes wrong.
  2. Sync'd both main and 23-fft-channelizer with remote repo. (git pull on each main/feature - response was up to date on both)
  3. Made sure both are saved to local disk.
  4. git rebase main

Now this is where the issues start. I get a conflict with the option to resolve in the VSCode IDE about which code to accept. It looks like this:

255: <<<<<<< HEAD
256:        samples = signal.convolve(samples, [1]*189, 'same')/189
257:       
258:        #for testing - log to file
259:        #self.f.write(samples.astype(np.float32).tobytes())
260:        
261:=======
262:        samples = signal.convolve(samples, [1] * 10, "same") / 189
263:
264:        # for testing - log to file
265:        # self.f.write(samples.astype(np.float32).tobytes())
266:
267:>>>>>>> 1f893dc (Make project runnable on Linux)

ISSUE

Neither of those lines can I find in the current local copy of that file, but it does exist on the repo at https://github/bigalnz/test_fft/blob/main/src/kiwitracker/sample_processor.py#L240

Q: So what is going on - why is that line not on my local copy and how can I resolve this?

Q: Are the two code snippets above diff's between two versions of main ?

Share Improve this question edited Jan 19 at 21:20 Al Grant asked Jan 19 at 21:12 Al GrantAl Grant 2,3741 gold badge31 silver badges66 bronze badges 3
  • git log --decorate --graph --oneline --all will show the true history of your repository and if there's any important changes in main. Clearly there are changes in main. – Schwern Commented Jan 19 at 21:15
  • Seems a lot of output to paste in here : pastebin/ME6tL5Hu - bear in main I am happy to write over main, but want to preserve the history - given main doesn't run I suppose I could accept either change? – Al Grant Commented Jan 19 at 21:18
  • Do yourself a favour and use a proper 3-way merge tool, like KDiff3, to resolve merge conflicts. – hlovdal Commented Jan 20 at 10:43
Add a comment  | 

2 Answers 2

Reset to default 1

Just merge main into the other branch using -s ours so that the operation actually does not affect the branch content as you have it.

git checkout x
git merge -s ours main -m "keeeping the history of main"
gig checkout main
git merge x # this should do a fast-forward

Q: Are the two code snippets above diff's between two versions of main ?

No. The conflict indicates both main and 23-fft-channelizer changed the same piece of code. From the conflict we see that 23-fft-channelizer changed it in 1f893dc Make project runnable on Linux

Q: So what is going on - why is that line not on my local copy and how can I resolve this?

From your git log we can see that main has a change in commit 269ea00 which is likely causing the conflict.

  • 269ea00 Updated matched filter ln 240 to samples = signal.convolve(samples, [1]*189, 'same')/189

You can use git log -p 269ea00 to see the content of that change and git log -p 1f893dc to see the change in 23-fft-channelizer. This will give you information about whether you want to keep it.

If you wish to see all the commits which are in main but not in 23-fft-channelizer, run git log 23-fft-channelizer..main. This will allow you to better decide if you want to throw out main's history. See gitrevisions - Specifying Ranges.


As you can see from your git log, Git history is connections between commits. But branches are just labels pointing at a particular commit. If you truly want to replace main with the history of 23-fft-channelizer simply rename the branches.

git branch -m main old-main
git branch -m 23-fft-channelizer main

Now main is what used to be 23-fft-channelizer, and old-main is what used to be main.

本文标签: Git Rebase Feature Branch to MainConflictStack Overflow