librelist archives

« back to archive

Git Question

Git Question

From:
Daniel Lepage
Date:
2010-06-01 @ 13:55
Does anyone know how to make Git handle local changes that are
identical to remote changes? Specifically, I'd like to be able to
modify a file in one repository, make identical changes to the same
file in another repo, and not have git complain about local changes if
I push changes from one to the other.

This comes up because I use TextMate for all my coding, even when I
need to actually run the code on a different machine, so I have a
TextMate macro bound to ctrl-s that scp's files to the remote machine
whenever I save them. However, I ALSO keep the code in a git repo so
that I can synchronize them easily if I make changes on the remote
machine without TextMate, or if I make edits on my machine when I
don't have internet access. But then git complains when I try to sync
them because many of the changes I made on my mac have already been
copied to the other, bypassing git. I'd rather not create a new git
checkin every single time I save; is there some other way around this?

Thanks,
Dan

Re: [cville] Git Question

From:
Ron DuPlain
Date:
2010-06-01 @ 14:24
Hi Dan,

On Tue, Jun 1, 2010 at 9:55 AM, Daniel Lepage <dplepage@gmail.com> wrote:
> This comes up because I use TextMate for all my coding, even when I
> need to actually run the code on a different machine, so I have a
> TextMate macro bound to ctrl-s that scp's files to the remote machine
> whenever I save them. However, I ALSO keep the code in a git repo so
> that I can synchronize them easily if I make changes on the remote
> machine without TextMate, or if I make edits on my machine when I
> don't have internet access. But then git complains when I try to sync
> them because many of the changes I made on my mac have already been
> copied to the other, bypassing git.

I imagine git is complaining because you are trying to
merge/fast-forward on a working tree that is dirty.  If that's not the
case, send some git output to help clarify what's happening.


> I'd rather not create a new git
> checkin every single time I save; is there some other way around this?

1. Edit directly on the remote machine.
  a. Use an editor like emacs -nw or vim via ssh in the terminal.
  b. Use sshfs to locally mount the remote directory, then use TextMate locally.
      (alternatively use davfs, but sshfs is easier to setup)

2. Use a bare git repository elsewhere (on the remote host, or github)
and git push to that.

In this case, you could continue scp'ing your files as needed, git
pushing to a bare repository, git checkout-ing in the remote
repository (to clean the working tree), and git pull-ing from the bare
repository to the remote repository.

To create the bare repository:

    $ mkdir -p src/repo
    $ cd src/repo/
    $ git init --bare
    Initialized empty Git repository in /home/rduplain/working/demo/src/repo/
    $

To push your local repo to the bare repository:

    $ git remote add bare example.org:src/repo
    $ git push --all bare

To re-sync your remote repository with the bare repository:

    $ git remote add bare ~/src/repo
    $ git checkout . # clear out scp'd changes
    $ git pull bare master # master or whatever the branch name is

Adjust paths and branches to taste.  I do 1a, but with a local
graphical editor like TextMate you might be more interested in 1b or
2. Even if option 2 here is not of interest, you might find that bare
repositories are quite useful.

Hope this helps.  If I'm way off base, send more details to help me
figure out what you're doing.

-Ron

Re: [cville] Git Question

From:
Daniel Lepage
Date:
2010-06-01 @ 14:59
Aha, excellent! I was missing 'git checkout .'.

1b isn't an option due to a bug in TextMate (which supposedly will be
fixed in TextMate 2, but TextMate 2 has been in development long
enough that it made Wired.com's 2009 Top 10 Vaporware list). Basically
if TextMate loses focus and then regains it it scans the currently
open files to make sure it doesn't need to update anything, but
there's no way to disable this if you're on a remote filesystem, so
every time you switch to a different app and then switch back it hangs
for as long as it takes to remote query every loaded file.

2 is more or less what I'm doing - I have a bare repo root, I make
changes in the working copy on my mac, and I push them to the root
repo with git push; the problem is that whenever I git pulled from the
root to the working copy on the linux box, it would complain about the
local changes. Ideally, I'd like git to detect that the remote changes
and the local changes are identical, but I didn't realize that just
calling "git checkout ." would erase the local changes.

Thanks!
Dan


On Tue, Jun 1, 2010 at 10:24 AM, Ron DuPlain <ron.duplain@gmail.com> wrote:
> Hi Dan,
>
> On Tue, Jun 1, 2010 at 9:55 AM, Daniel Lepage <dplepage@gmail.com> wrote:
>> This comes up because I use TextMate for all my coding, even when I
>> need to actually run the code on a different machine, so I have a
>> TextMate macro bound to ctrl-s that scp's files to the remote machine
>> whenever I save them. However, I ALSO keep the code in a git repo so
>> that I can synchronize them easily if I make changes on the remote
>> machine without TextMate, or if I make edits on my machine when I
>> don't have internet access. But then git complains when I try to sync
>> them because many of the changes I made on my mac have already been
>> copied to the other, bypassing git.
>
> I imagine git is complaining because you are trying to
> merge/fast-forward on a working tree that is dirty.  If that's not the
> case, send some git output to help clarify what's happening.
>
>> I'd rather not create a new git
>> checkin every single time I save; is there some other way around this?
>
> 1. Edit directly on the remote machine.
>  a. Use an editor like emacs -nw or vim via ssh in the terminal.
>  b. Use sshfs to locally mount the remote directory, then use TextMate locally.
>      (alternatively use davfs, but sshfs is easier to setup)
>
> 2. Use a bare git repository elsewhere (on the remote host, or github)
> and git push to that.
>
> In this case, you could continue scp'ing your files as needed, git
> pushing to a bare repository, git checkout-ing in the remote
> repository (to clean the working tree), and git pull-ing from the bare
> repository to the remote repository.
>
> To create the bare repository:
>
>    $ mkdir -p src/repo
>    $ cd src/repo/
>    $ git init --bare
>    Initialized empty Git repository in /home/rduplain/working/demo/src/repo/
>    $
>
> To push your local repo to the bare repository:
>
>    $ git remote add bare example.org:src/repo
>    $ git push --all bare
>
> To re-sync your remote repository with the bare repository:
>
>    $ git remote add bare ~/src/repo
>    $ git checkout . # clear out scp'd changes
>    $ git pull bare master # master or whatever the branch name is
>
> Adjust paths and branches to taste.  I do 1a, but with a local
> graphical editor like TextMate you might be more interested in 1b or
> 2. Even if option 2 here is not of interest, you might find that bare
> repositories are quite useful.
>
> Hope this helps.  If I'm way off base, send more details to help me
> figure out what you're doing.
>
> -Ron
>

Re: [cville] Git Question

From:
Matt Dawson
Date:
2010-06-01 @ 18:08
Not that this is in the least bit helpful of an observation, but I'm
very surprised git doesn't handle this more gracefully. In fact, I had
to quickly recreate a scenario like this just to confirm. As Ron
mentioned:

> I imagine git is complaining because you are trying to
> merge/fast-forward on a working tree that is dirty.

and that does seem to be the case. Crazy! With all of the intelligent
fast-fowarding that Git's able to do, I'm shocked it doesn't do some
quick diffing of the remote working tree against the target commit.

Matt


On Tue, Jun 1, 2010 at 10:59 AM, Daniel Lepage <dplepage@gmail.com> wrote:
> Aha, excellent! I was missing 'git checkout .'.
>
> 1b isn't an option due to a bug in TextMate (which supposedly will be
> fixed in TextMate 2, but TextMate 2 has been in development long
> enough that it made Wired.com's 2009 Top 10 Vaporware list). Basically
> if TextMate loses focus and then regains it it scans the currently
> open files to make sure it doesn't need to update anything, but
> there's no way to disable this if you're on a remote filesystem, so
> every time you switch to a different app and then switch back it hangs
> for as long as it takes to remote query every loaded file.
>
> 2 is more or less what I'm doing - I have a bare repo root, I make
> changes in the working copy on my mac, and I push them to the root
> repo with git push; the problem is that whenever I git pulled from the
> root to the working copy on the linux box, it would complain about the
> local changes. Ideally, I'd like git to detect that the remote changes
> and the local changes are identical, but I didn't realize that just
> calling "git checkout ." would erase the local changes.
>
> Thanks!
> Dan
>
>
> On Tue, Jun 1, 2010 at 10:24 AM, Ron DuPlain <ron.duplain@gmail.com> wrote:
>> Hi Dan,
>>
>> On Tue, Jun 1, 2010 at 9:55 AM, Daniel Lepage <dplepage@gmail.com> wrote:
>>> This comes up because I use TextMate for all my coding, even when I
>>> need to actually run the code on a different machine, so I have a
>>> TextMate macro bound to ctrl-s that scp's files to the remote machine
>>> whenever I save them. However, I ALSO keep the code in a git repo so
>>> that I can synchronize them easily if I make changes on the remote
>>> machine without TextMate, or if I make edits on my machine when I
>>> don't have internet access. But then git complains when I try to sync
>>> them because many of the changes I made on my mac have already been
>>> copied to the other, bypassing git.
>>
>> I imagine git is complaining because you are trying to
>> merge/fast-forward on a working tree that is dirty.  If that's not the
>> case, send some git output to help clarify what's happening.
>>
>>> I'd rather not create a new git
>>> checkin every single time I save; is there some other way around this?
>>
>> 1. Edit directly on the remote machine.
>>  a. Use an editor like emacs -nw or vim via ssh in the terminal.
>>  b. Use sshfs to locally mount the remote directory, then use TextMate locally.
>>      (alternatively use davfs, but sshfs is easier to setup)
>>
>> 2. Use a bare git repository elsewhere (on the remote host, or github)
>> and git push to that.
>>
>> In this case, you could continue scp'ing your files as needed, git
>> pushing to a bare repository, git checkout-ing in the remote
>> repository (to clean the working tree), and git pull-ing from the bare
>> repository to the remote repository.
>>
>> To create the bare repository:
>>
>>    $ mkdir -p src/repo
>>    $ cd src/repo/
>>    $ git init --bare
>>    Initialized empty Git repository in /home/rduplain/working/demo/src/repo/
>>    $
>>
>> To push your local repo to the bare repository:
>>
>>    $ git remote add bare example.org:src/repo
>>    $ git push --all bare
>>
>> To re-sync your remote repository with the bare repository:
>>
>>    $ git remote add bare ~/src/repo
>>    $ git checkout . # clear out scp'd changes
>>    $ git pull bare master # master or whatever the branch name is
>>
>> Adjust paths and branches to taste.  I do 1a, but with a local
>> graphical editor like TextMate you might be more interested in 1b or
>> 2. Even if option 2 here is not of interest, you might find that bare
>> repositories are quite useful.
>>
>> Hope this helps.  If I'm way off base, send more details to help me
>> figure out what you're doing.
>>
>> -Ron
>>
>