I have a branch off of main called AI_feature.' When I first created the branch, it ended up copying the commits from main along with it. Now that I am trying to merge the branch back into main, I was asked to only commit files that were relevant to the feature I developed. Confused, I looked at the 'Changes' tab in Gitlab and discovered that Git decided that every file in the repo was a new change despite my not touching them. I figured I would use rebase to remove those commits since they belong to the main repo rather than my branch. The problem is that I don't really know what I am doing...
I used
git rebase --interactive main
to begin. This opens up the git-rebase-todo file in vim. I used
:set number
and
:1,55s/pick/d/g
to view line numbers and drop all commits that preceded mine. Saving the file continues the rebase until some merge conflicts arise. This is where I get lost.
Git is telling me that there are conflicts with the first version of the files I created and the latest ones. But I am not sure how to tell it to ignore early versions and go with the latest files.
In the git-rebase-todo file, I had some ideas:
- Drop the irrelevant, preceding commits and squash my commits like so:
drop <hash_of irelevant>
pick <1st of my commits>
s <hash of next commits>
...
s <hash of my latest commits>
Drop all commits but my latest one.
Cry because I wasted my morning on this and its a Friday.
What do I need to do in order for git to drop commits preceding mine and accept the latest versions of my files as the final versions before merging? And how can I avoid the preceding commits issue in the future?