15

I just want to edit/amend the text of an older Git commit.

I ran the following:

$ git rebase -i a41a407d6f53328d49267e6a8429b9492f023629
error: The following untracked working tree files would be overwritten by checkout:
    admin/roles/allowassign.php
    admin/roles/allowoverride.php
    admin/roles/assign.html
    admin/roles/assign.php
    admin/roles/manage.html
    admin/roles/manage.php
    admin/roles/managetabs.php
    admin/roles/override.html
    admin/roles/override.php    
Aborting
could not detach HEAD       

However, git status does not list any untracked files:

$ git status
On branch dev
nothing to commit, working directory clean

Note, that admin/roles is a submodule of the repository:

$ git submodule
 77c5addc1b210256da9171e3b286ffa5addd2478 admin/roles (heads/dev)

And listing ignored files:

$ git status --ignored
On branch duf-moodle-dev
Ignored files:
  (use "git add -f <file>..." to include in what will be committed)

        blocks/moodleblock.class.php.bak
        filter/tex/mimetex.exe
        lib/smarty/COPYING.lib

nothing to commit, working directory clean

Saving GIT stash has no result:

$ git stash save --include-untracked
No local changes to save

I was reading, that integrating into Explorer Shell, can have such result. Currently Git Extensions, GIT GUI, and SmartGIT are integrated into context shell. This may cause problem?

My proposal is, that the problem origin is the use of submodules. I keep some changes as submodules.

Any ideas why the rebase interactive gives be the error and how to fix it?

Also, there would be even fine to have a solution to edit/amend an older commit description without using rebase...

klor
  • 1,237
  • 4
  • 12
  • 37
  • What does `git status --ignored` show? – Biffen Mar 23 '15 at 15:16
  • Added the `git status --ignored` result to original post. Nothing common with the admin/roles/... – klor Mar 24 '15 at 09:05
  • @klor Since my answer didn't help, I'll delete it, at least for now. – jub0bs Mar 24 '15 at 09:51
  • I plan to stop using submodules. I hope, if I stop using submodules, such problems will be gone. However there is no easy way to make merge submodule repository to my parent repository :-( – klor Mar 24 '15 at 13:42
  • However, when I try to merge a submodule to main repo, then rebase & stick the oldest commit of submodule, to last commit of main repo, I get the "error: The following untracked working tree files would be overwritten by checkout". The "Catch-22" is closed. Any idea? – klor Mar 24 '15 at 15:43

4 Answers4

6

Solution was to remove the submodule from main repo (unsubmodule). Then it was possible to do rebase.

klor
  • 1,237
  • 4
  • 12
  • 37
  • 4
    Note that this can be done via `git submodule deinit ` on the current version of git. After the rebase, use `git submodule init; git submodule update` to bring back the submodule. – splicer Sep 30 '17 at 01:00
3

I had a similar problem, but in my case it was caused by changing letter case in file names while using Windows (which seems to get git confused about it). I solved by using a virtualised linux (could be a docker container), checking out that branch and doing the rebase from there.

Victor Basso
  • 5,556
  • 5
  • 42
  • 60
  • 1
    Same problem for me on windows. I then checked out the base branch and cherry-picked the other commits on top of it. – User Rebo Dec 24 '20 at 10:28
2

For me rebase used to work fine even with untracked files until I did some unusual steps day before (resetting head on different branch etc.), and suddenly rebase on different branch (onto master) stopped working.

This helped:

git fetch --all
git reset --hard origin/master

Credit: https://ageekandhisblog.com/git-force-overwrite-of-untracked-working-tree-files/

Shahid
  • 23
  • 3
0

I had this problem when rebasing in Drupal. I had to remove the file it complained about, commit the removal, rebase and resolve the merge conflicts by skipping patches, then delete the commit I had just made.

Liam Morland
  • 83
  • 1
  • 4