1

I'm new to git and astounded it's so revered considering the complexity of this simple task.

I googled it, and came up with a few results that ultimately said run this command:

git filter-branch --subdirectory-filter your_dir -- -- all

However it results in:

C:\tmp\w2 [master]> git filter-branch --subdirectory-filter IndigoServices -- --all
Usage: git core\git-filter-branch [--env-filter <command>] [--tree-filter <command>]
        [--index-filter <command>] [--parent-filter <command>]
        [--msg-filter <command>] [--commit-filter <command>]
        [--tag-name-filter <command>] [--subdirectory-filter <directory>]
        [--original <namespace>] [-d <directory>] [-f | --force]
        [<rev-list options>...]
C:\tmp\w2 [master]> git filter-branch --subdirectory-filter IndigoServices -- -- all
fatal: ambiguous argument 'all': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

Is there an easy way to do what I'm trying to achieve?

NibblyPig
  • 51,118
  • 72
  • 200
  • 356
  • "I'm new to git and astounded it's so revered considering the complexity of this simple task." We all were once. Some of us are still with you. – John Zwinck Aug 02 '13 at 11:37
  • @SLC First of all, please clarify what you're trying to do, the title does not provide enough information. What is this "simple task" that you're trying to do? It sounds like you might be thinking in terms of SVN and the way it handles subdirectories, but without more info I can't be sure. Second, let me get this clear: **GIT IS AWESOME**! Totally ***beats the snot out of any traditional centralized SCM*** like SVN, TFS, etc. Wait until you discover **THE POWER OF REBASE**! Check out my profile for all the resources you need to become a **GIT GOD**! –  Aug 02 '13 at 11:51
  • @Cupcake I'm not sure how to clarify further. I have a repository on git. I just made another repository. I want to move a folder from the old repository to the new repository, but keep all of the commit history. Perhaps you can convince me how great git is by helping me find an answer to this seemingly simple task, while I explain to my boss that I've wasted an hour so far...! – NibblyPig Aug 02 '13 at 11:55
  • @SLC I'm still not entirely clear on what you're trying to do. How did you make this new repository? Did you clone it from the old one? Then it has all the history already, including the history of the folder you're trying to move. If not, you can add the old repo as a remote and fetch all of its history that way. Is this something that you could do in a different manner in like SVN or TFS or something? Let me ask this. In SVN, subdirectories can represent branches, but that's not how Git represents branches. Is that what you're thinking of, subdirectories as branches? –  Aug 02 '13 at 12:04
  • @SLC or do you have a subdirectory in your project, like say `/submodule`, and only a subset of the commits of the entire repo are associated with it, and you want to move that subdirectory with its subset of history into a new history in another repo? Can you show us a commit graph of what you're trying to do in that case? `git log --graph --oneline -- `? You can remove sensitive information from the graph messages if you need to. –  Aug 02 '13 at 12:11
  • @SLC never mind, I think I'm starting to get what you're trying to do, will take another look later. –  Aug 02 '13 at 12:22
  • @SLC do you realize that you have a typo in your command `git filter-branch --subdirectory-filter your_dir -- -- all`? You're using `-- -- all` instead of `-- --all`, the `--all` is an option flag. ***That's what the error message is trying to tell you***: "fatal: ambiguous argument 'all'". Not sure if that will solve your higher level problem though. Also, have you read how the command that you're using works in the [official Linux Kernel Git documentation for `filter-branch`](https://www.kernel.org/pub/software/scm/git/docs/git-filter-branch.html)? –  Aug 02 '13 at 15:39
  • Sorry, if it wasn't clear, I tried both because I wasn't sure which was correct, which is what's displayed in my question. – NibblyPig Aug 02 '13 at 15:58
  • the correct tool for the job is `git subtree`, do a `git subtree split` to generate a separate history for your folder. You can then merge this history into the other repo. You will need to read up on basic git principles – what you are trying is not a simple task, but is a little bit more complicated because you are trying to change history, which in some ways goes against the nature of git. – Chronial Aug 02 '13 at 21:22
  • @Chronial it's not documented in the official Linux Kernel docs, though I [found it on GitHub](https://github.com/apenwarr/git-subtree). Is it a plugin? –  Aug 02 '13 at 21:57
  • @SLC I think I might see a problem. In your first example, do you see the arguments that `filter-branch` takes? The last line says `[...]`, but that's not what the current [official Linux documentation for `filter-branch`](https://www.kernel.org/pub/software/scm/git/docs/git-filter-branch.html), it gives the last line of arguments as ` [--] […]`. Which version of Git are you using (do `git --version`). Basically, it looks like the `--` between the directory and the `--all` flag might be invalid. –  Aug 03 '13 at 02:47
  • @SLC for what it's worth, I ran `git filter-branch --subdirectory-filter -- --all` in a practice repo, and I got the expected result, `` became the new root of the repo, and had only its own associated history. I'm using msysgit Bash version 1.8.3. I see that you're using PoshGit, though I don't know which version of Git. Maybe there's a difference? –  Aug 03 '13 at 03:43
  • 1
    @Cupcake `git subtree` is kind of a plugin. It is part of [git contrib](https://github.com/git/git/tree/master/contrib/subtree) now, the repo you linked to is obsolete. It is part of the standard git package on a lot of distributions. It is also the correct tool for the job, because `filter-branch` will remove everything but the folder, which is not what OP wants, so he would have to undo that afterwards. – Chronial Aug 04 '13 at 02:58
  • @SLC found [this answer](http://stackoverflow.com/questions/359424/detach-subdirectory-into-separate-git-repository/359759#359759) and [this answer](http://stackoverflow.com/questions/359424/detach-subdirectory-into-separate-git-repository/17864475#17864475) to [Detach subdirectory into separate Git repository](http://stackoverflow.com/questions/359424/detach-subdirectory-into-separate-git-repository), have you tried `git subtree` yet? –  Aug 10 '13 at 19:32
  • [Atlassian has a blog post about using `git subtree`](http://blogs.atlassian.com/2013/05/alternatives-to-git-submodule-git-subtree/), not sure if it's applicable to your situation though. –  Aug 10 '13 at 19:33

0 Answers0