Proper steps to rebase a branch/PR

I have a love/hate relationship with git, and I never seem to use the right commands. I have a PR here:

That PR is a merge from my own fork and branch:

Here’s my problem. If I do a git fetch --all and then rebase, I get changes in 3rdparty and apps that I didn’t make. Also, it is requested that you run /build/autoloaderchecker.sh and commit that change . . . but now, my branch and PR contain changes to the autoloader files.

I’ve been trying to rebase my branch all morning. Even though I only changed 5 files, my final commit has 30 files changed, 59 insertions, and 59 deletions. Wut?

Could someone list out the proper commands and the order in which they should be executed in order to properly rebase a branch on the upstream repo without including files I didn’t change? I have this problem every time I go to rebase my branches, and I never manage to get it right.

I’m doing this:

git branch [my-branchname]
git fetch --all

// Might be unnecessary
git submodule update --recursive

git rebase -i upstream/master
./build/autoloaderchecker.sh
git commit -S -a -m 'rebase'
git push origin [my-branchname] --force-with-lease

git commit -S --all -m is evil.

  1. git status to show all modified files.
  2. git add x/y/z to add only your changed files.
  3. git commit -S -m "blublub" to commit the result.
./build/autoloaderchecker.sh

You need to run this command if you added a new file for composer to recognize.
If you did not add a new file, don’t run it.

1 Like

Those really aren’t complete instructions, but I think I’m still following you. Unfortunately, I’m still getting errors about 3rdparty being modified. I. Did. Not. Change. 3rdparty. This happens every time I try to rebase, and it’s getting very frustrating.

Here are the commands I’m running:

git branch [branchname]
git reset --hard [most-recent-commit]
git fetch --all
git submodule update --recursive
git rebase -i upstream/master
git add [just] [the] [files] [I] [changed]
git commit -S -m "rebase"

I immediately get:

On branch [branchname]
Your branch and 'origin/[branchname]' have diverged,
and have 722 and 1 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   3rdparty (new commits)

no changes added to commit (use "git add" and/or "git commit -a")

If I run git diff --name-only HEAD HEAD~2, I get the following:

// My files
config/config.sample.php
lib/private/Files/AppData/AppData.php
lib/private/Files/Cache/LocalRootScanner.php
lib/private/SystemConfig.php
tests/lib/Files/AppData/AppDataTest.php

// I didn't touch these
apps/files_reminders/lib/Controller/ApiController.php
apps/files_reminders/openapi.json

-a, means all files. Try without :wink:

I did. In my second set of instructions, I omitted the -a on commit. Still the same issues.

EDIT: I guess I forgot to omit the -a it when I posted my reply, but I ran it without, and I am still blocked from committing.

Please join https://cloud.nextcloud.com/call/xs25tz5y to figure it out in a call.

Thank you so much for hopping on a call with me. That was extremely helpful and unexpected. For posterity sake:

// Only if you're like me and messed up your branch:
git branch [branchname]
git reset --hard [most-recent-commit]

git fetch --all
git restore 3rdparty
git rebase -i upstream/master
git push origin [branchname] --force-with-lease

If you have the time, could you explain in simple terms why 3rdparty and apps cause issues? I mean, I understand 3rdparty because they’re submodules (shouldn’t git submodule update --recursive fix that?), but apps isn’t.

I don’t know. It looked like all files in 3rdparty were modified. In the server repository, 3rdparty is a reference to a git submodule.

git submodule update --init should reset the 3rdparty to the right state.