Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3985174
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:51:29+00:00 2026-05-20T05:51:29+00:00

Yesterday I did one of these operations (see code snippet below) on my git

  • 0

Yesterday I did one of these operations (see code snippet below) on my git repo in order to effectively move my project up a few folders in the folder hierarchy. This basically lists all files and adds a prefix folder name to them and updates the index accordingly.

Old layout:

+ Root
  - Sublevel 1
    - Sublevel 2
      - .git was here

New, desired layout:

+ Root
  - .git moved to here, so prefix all index files with "Sublevel 1/Sublevel 2/"
  - Sublevel 1
    - Sublevel 2

Command:

git filter-branch --index-filter '
    git ls-files -s | sed "s-\t-&newRoot/sub1/sub2/-" |
        GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info && mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE
    ' HEAD

However, this command, unbeknownst to me, only modified the master branch. I have about 8 other branches off of master. When I checkout one of these other branches, it checks out all files (some 11,000) in my repo in their original folder structure at the new root folder level where I moved the .git folder to.

How do I repair this snafu? The damage is already done. I have a backup of the .git folder before I did ran the filter-branch but I have commits after this backup was made, not many but enough to warrant finding a patch-like fix on the current repo. I don’t see any obvious branch-specific arguments to the filter-branch command.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T05:51:30+00:00Added an answer on May 20, 2026 at 5:51 am

    filter-branch will “rewrite only the positive refs mentioned in the command line“. So you need to specify “–branches” to rewrite all branches. You specified HEAD, so it just rewrote HEAD (i.e. master)

    After you run filter-branch, the original refs are backed up in refs/original (i.e. refs/original/master is master before filtering): the objects are still available, and I believe the reflogs are kept intact too, so recovering from a bad filter-branch operation is fairly straightforward.

    So your options are:

    • Undo the filter-branch command by checking out master and doing git reset --hard refs/original/master

    • Filter the other branches so they are transformed as well: redo the filter-branch command but specify --branches --not master instead of HEAD, or more safely by naming the branches to be modified explicity

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yesterday, I found myself writing code like this: SomeStruct getSomeStruct() { SomeStruct input; cin
( This question about refactoring F# code got me one down vote, but also
I had this code working yesterday, but it seems like I edited it a
I worked on this yesterday about 5 hours and got the code to work
Yesterday I started working on my iPhone project again. I'm building a game with
I have a git branch (called v4), that was made from master just yesterday.
I made a question yesterday about this, but I did some changes in my
Yesterday I wanted to add a boolean field to an Oracle table. However, there
Yesterday, I asked this question and never really got an answer I was really
Yesterday, I discovered the Subversion (SVN) blame feature, and I was wondering, is this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.