开发者

command line version control with Java -- dealing with lots of nested dirs

Using command line git with Java. Our project has tons of nested packages which of course means lots of nested directories.

Typing out these directories on the command line is becoming a PITA and seems unavoidable for certain non-everyday operations like "git rm". Especially when I move stuff around in Eclipse then need to play catch-up at the command line, but the files don't exist anymore (can't use shell expansion or *). Also, shell expansion doesn't account for ignored files, and sending ignored files to a git command causes the command to abort (rightf开发者_StackOverflowully). Not interested in IDE integration for reasons out of scope of this question.

Anyone put any thought into making this easier?

I'm on win7/powershell, but am open to suggestions using bash or batch as well.


Not familiar with win7/powershell. Assuming your class names are unique, in bash you can find files with

find . -name SomeFile.java

Then you could "git rm" them with

git rm $(find . -name SomeFile.java)

Of course, if you don't want to type "find . -name" each time, you could create a function in your .bashrc to simplify that. Does powershell support something similar? If not, what about looking into cygwin, which allows you to run bash?

EDITED

If your class names aren't unique, this approach won't work so well.


I haven't used git before, but I use Perforce. I assume you need to reference a number of directories and you can't use wildcards for some reason. Then in PowerShell, you can use constructs like this:

## Find all directories named "test*"
dir * -inc test* -r | ? {$_.PSIsContainer} | % {git <some command> $_.FullName}

## Find all files and directories named "test*.*"
dir * -inc test*.* -r | % {git <some command> $_.FullName}

You could also write a wrapper function to make this easier. Here is something to get you started.

Function git {
    param(
        [Parameter(Position = 0, Mandatory = $true)]
        [String]$Command
        ,
        [Alias("PSPath")]
        [Parameter(Position = 1, ValueFromPipelineByPropertyName = $true)]
        [String[]]$Path
    )

    process {
        if ($Path) {
            $Path | {git.exe $Command $_}
        } else {
            git.exe $Command
        }
    }
}


I didn't know about git add -A -- and after using this for a couple days I haven't had much as much path frustration. Will report back.


If you want to avoid typing in all the paths, you could use TortoiseGit and do the management via a GUI.

I like using the command line too, but when it comes to certain cases (e.g. reverting 20 files at once), I find it easier to check the files in the revert dialog and simply click ok. For me, TortoiseGit is no replacement for the Git console but a very convenient extension to it.

Unfortunately, your mentioned use case (removing multiple files at once) cannot be achieved with TortoiseGit. If I had to remove a bunch of files at once, I'd ask git to tell me which files are currently versioned (git ls-files), pipe that list into a file, edit it and then do a git rm for every file left in the edited file.


Have you tried EGit? It's not the most spectacular git UI you've ever seen but if you're already using eclipse, it will make some things easier. It's also nice to see the little mini-icons in Eclipse itself showing which files have changed and which haven't.


Have you tried the git fronted git gui? It usually comes with git and is a great help to quickly stage a bunch of files.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜