I currently have a PR open on a repo where the maintainer prefers to have all PR's as a single commit. This heavily effects my workflow when making changes on request from the maintainer. I have a desktop and laptop that I use to work from.
This may not be the "right" idea, but I consider my desktop the "homebase" or "original" machine. My laptop is always tracking remote branches that originated from that machine.
Lately, I've been running into this problem where I will make a change (either on my laptop or desktop) and have trouble rebasing the same branch on a different machine. I'm not an expert at git, but I think this has something to do with trying to rebase changes on amended commits. I'll give you an example:
Desktop on a branch with a single commit and an open PR
# Make requested changes
> touch changes.txt
> git add changes.txt
> git commit --amend
> git push -f origin PR_branch
This updates my PR and launches the automated testing scripts. Now, I have a long conference call I have to go to and can still work while listening, so I grab my laptop and navigate to my repo on a branch that is tracking the branch I just pushed to
Laptop on a branch tracking the remote branch with amended commit
> git pull origin PR_branch
From gitlab:user/repo
* branch PR_branch -> FETCH_HEAD
CONFLICT (add/add): Merge conflict in changes.txt
Auto-merging changes.txt
Automatic merge failed; fix conflicts and then commit the result.
> git status
On branch PR_branch
Your branch is ahead of 'upstream/devel' by 1 commit.
(use "git push" to publish your local commits)
You have unmerged paths.
(fix conflicts and run "git commit")
(use "git merge --abort" to abort the merge)
Unmerged paths:
(use "git add <file>..." to mark resolution)
both added: changes.txt
At this point the only way I've found to resolve this is by doing:
# Still on my laptop
> git checkout --theirs changes.txt
> git add changes.txt
> git commit -m "Fixed merge conflict between desktop and laptop"
Now what I'll do is reset --hard
to the previous commit hash which is the amended commit that has the most recent changes from my desktop. My gut feeling is that this is flat out wrong.
> git reset <previous commit hash> --hard
Now I have the updated changes from my desktop on my laptop and everything seems kosher. I have done this back and forth from my desktop -> laptop -> desktop -> laptop -> desktop (that many times). Is there a more idiomatic way to handle this, am I messing something up in my git history?