3

I'm quite new to git and trying to learn some of the more advanced ideas and solutions.

The following is a portion of my local repo structure.

Root
|- Dev
|--Components
|- Live
|- Offsite.

This represents a base project where I will be building one instance of a web project in Dev and then compiling it into live. This means that DEV is a highly volatile folder.

Over the last few days I've added and removed many elements from Dev/components using Bower.js

I've been trying to use

git ls-tree Dev/Components

to view the top level tree of that directory to see if I only have the most current elements in that directory. This is returning: fatal: Not a valid object name tree

So, my question is what's the correct call to make?

(Alternatively, is there a better way to compare a snapshot of the current repo with a snapshot of the directory)

Crispen Smith
  • 513
  • 4
  • 20
  • 1
    Uhm, `ls` or `git diff`? Not sure what you are trying to do. – poke Jun 27 '13 at 19:27
  • Not quite sure what you want, but ``git ls-tree`` [only works with git refs](http://stackoverflow.com/a/10083169/1048479). Are you trying to compare the directories to see what has changed between commits? – Nick Tomlin Jun 27 '13 at 19:30
  • 1
    try `git ls-tree HEAD Dev/Components` – Fredrik Pihl Jun 27 '13 at 19:31
  • Given two shell windows, I'd like to be able to have one shell window return the results of ls on the actual working directory Dev/Components and have another one show the results of git ls-tree (whatever) that looks at the same place within the repo. I guess the issue is my limited understanding of git refs. What's the correct ref in this instance, that might have been a better starting point. – Crispen Smith Jun 27 '13 at 19:35
  • 1
    To list all files in your repo (i.e. files added to src-control) use `git ls-tree --full-tree -r HEAD` This you can compare with the output of `ls`. But I don't see the need for this approach... – Fredrik Pihl Jun 27 '13 at 19:38
  • Fredrik, thank you. Almost exactly what I needed. git ls-tree HEAD Dev/Components confirmed the existence of the subdirectory and doing it with -r showed all recusive contents. I just need to find a way to only go 1 level deep instead of full recursion. – Crispen Smith Jun 27 '13 at 19:39
  • As I said, I'm still quite new to git and still figuring out how to use this thing; add to that the fact that this directory is extremely volatile and I'm not sure I've been removing things when I've needed to; I'm a little worried that the current repo is carrying a lot of extra garbage. Without knowing better options this was what made sense to me to scan for things that I might have left behind accidentally. I suspect `git diff` is probably a better option, but didn't know of it when I authored the question. – Crispen Smith Jun 27 '13 at 19:43
  • GIT takes some time getting used to, but when you understand the basics, you will never go back to another SCM again. One of the best free books on GIT is [this one](http://git-scm.com/book). Also, have a look at the `git ls-files` command. – Fredrik Pihl Jun 27 '13 at 19:47
  • I'll read through that book, I'd started learning git via github and only really got add and commit down until I needed some additional pieces today. – Crispen Smith Jun 27 '13 at 19:57
  • I think the real question here is: Why do you have a Dev and Live folder. Instead of Dev and Live branch? – Loïc Faure-Lacroix Jun 27 '13 at 21:03
  • Honestly, inexperience. However, there are some factors pushing me that direction in the Non-repo'ed file structure. 1. Live wants to have concatenated and minified JSS and CSS, this also affords me the luxury of pushing redundant JS modules to the browser in DEV and removing them during build. 2. I'm using a PaaS cloud as a server for live which I access through a CLI so it's easier to have distinct folder that I can push to the server as a whole. 3. It creates a very clean separation of concerns within the IDE while building things. I'm happy to explore branches and use them as well. – Crispen Smith Jun 28 '13 at 01:10
  • To comment again on Loic Faure-Lacroix's comment about branching instead of directories, I've done some serious thinking and research into the question of branching and at this time I feel justified in keeping it as seperate dirs, they serve different purposes and it's a red herring anyway as the question could have just as easily asked about the /functions/ and /css/ directories. – Crispen Smith Jul 01 '13 at 15:16

1 Answers1

2

Specify the commit then the paths - eg: git ls-tree HEAD:Dev/Components or git ls-tree master~4:Dev/Components

What you are after is the documentation on specifying revisions in git. See git rev-parse which has the details on the many ways to specify a revision or fragment of one.

patthoyts
  • 32,320
  • 3
  • 62
  • 93