threads / discuss / 14248

git push requires a subsequent git reset --hard ?

Subject: git push requires a subsequent git reset --hard ?

## tl;dr

6 messages between Jul 1, 2008 and Jul 4, 2008.

replies: 5people: 4as markdown or json

Neshama Parhoti· Jul 1, 2008, 16:51 UTC · lore
Hi all,

I took with me a copy of a local repository to a week away from my station (just rsync'ed it to my laptop).

On my return, I just "git push myuser@my-station:/my/git/repo" from my laptop. It seemed to work with no probs. On my station the git repo got the new commits, as I can see in git-log, but the actual files were left untouched.

So I need to do something like "git reset --hard HEAD" to get the changes into the local files.

Is that considered normal ?
or did I do something wrong ?

Thanks, pnesh

Jeff King· Jul 1, 2008, 17:19 UTC · re: Neshama Parhoti · lore

Re: git push requires a subsequent git reset --hard ?

On Tue, Jul 01, 2008 at 07:51:26PM +0300, Neshama Parhoti wrote:
Show 11 quoted lines
> On my return, I just "git push myuser@my-station:/my/git/repo" from my laptop.
> It seemed to work with no probs.
> On my station the git repo got the new commits, as I can see in
> git-log, but the actual files were left untouched.
> 
> So I need to do something like "git reset --hard HEAD" to get
> the changes into the local files.
> 
> Is that considered normal ?
> 
> or did I do something wrong ?
See:
  http://git.or.cz/gitwiki/GitFaq#head-b96f48bc9c925074be9f95c0fce69bcece5f6e73
  and
  http://git.or.cz/gitwiki/GitFaq#head-46de97a5ac549d3adf406c22674b3325ae25d09c
What you did is OK, but there is a better way to do it.
-Peff
Jakub Narebski· Jul 1, 2008, 17:29 UTC · re: Neshama Parhoti · lore

Re: git push requires a subsequent git reset --hard ?

"Neshama Parhoti" <pneshama@gmail.com> writes:
Show 13 quoted lines
> I took with me a copy of a local repository to a week away from my station
> (just rsync'ed it to my laptop).
> 
> On my return, I just "git push myuser@my-station:/my/git/repo" from my laptop.
> It seemed to work with no probs.
>
> On my station the git repo got the new commits, as I can see in
> git-log, but the actual files were left untouched.
> 
> So I need to do something like "git reset --hard HEAD" to get
> the changes into the local files.
> 
> Is that considered normal ?

This is considered normal. Push would never touch index nor working area (although if you are the only user, and you know what you are doing, you can add "git reset --hard HEAD" to post-receive hook). It is the only way: "push" cannot be opposite of "pull" and do a merge because there is nobody to resolve conflict on remote side.

So you should either do mirroring (1:1 refspec) push into bare repository (without working directory), or push into remotes section, remotes/satellite or remotes/mothership, like shown in GitFaq, below.

See also:
* "Why won't I see changes in the remote repo after "git push"?"
  http://git.or.cz/gitwiki/GitFaq#head-b96f48bc9c925074be9f95c0fce69bcece5f6e73
* "How would I use "git push" to sync out of a firewalled host?"
  http://git.or.cz/gitwiki/GitFaq#head-46de97a5ac549d3adf406c22674b3325ae25d09c
-- 
Jakub Narebski
Poland
ShadeHawk on #git
Dmitry Potapov· Jul 2, 2008, 13:36 UTC · re: Jakub Narebski · lore

Re: git push requires a subsequent git reset --hard ?

On Tue, Jul 01, 2008 at 10:29:38AM -0700, Jakub Narebski wrote:
> 
> This is considered normal.  Push would never touch index nor working
> area (although if you are the only user, and you know what you are
> doing, you can add "git reset --hard HEAD" to post-receive hook).

Doing "reset --hard" makes all your uncommit changes to be lost. OTOH, if you push on the local branch assotiated with HEAD then recovering all uncommit changes later will not be easy either. So, I wonder, if git push should require --force if you want to push to the HEAD branch of a non-bare repo. It will be at least some warning (especially for novices) to not to do that, and those who really want to understand what they are doing can use --force.

Dmitry
Dmitry Potapov· Jul 2, 2008, 13:45 UTC · re: Jakub Narebski · lore

Re: git push requires a subsequent git reset --hard ?

On Tue, Jul 01, 2008 at 10:29:38AM -0700, Jakub Narebski wrote:
>_
> This is considered normal.  Push would never touch index nor working
> area (although if you are the only user, and you know what you are
> doing, you can add "git reset --hard HEAD" to post-receive hook).

Doing "reset --hard" makes all your uncommitted changes to be lost. OTOH, if you push on the local branch associated with HEAD then recovering all uncommitted changes later will not be easy either. So, I wonder, if git push should require --force to push to HEAD of a non-bare repository. It will be at least some warning (especially for novices) to not to do that, and those who understand what they are doing can use --force.

Dmitry

← back to recent threads