threads / discuss / 21805

Newbie "svn update" question

Subject: Newbie "svn update" question

## tl;dr

4 messages between Dec 1, 2009 and Dec 1, 2009.

replies: 3people: 3as markdown or json

Mikko Oksalahti· Dec 1, 2009, 09:25 UTC · lore
Hi,

I just started using git for my personal projects at home. Basic usage seems pretty straight-forward as well as setting up everything. However, I have a simple question about how do I mimic an "svn update" command on a locally created repository. Here's what I do:

some_existing_project_dir> git init some_existing_project_dir> git add .

(about 1000 files added...)
some_existing_project_dir> git commit -a -m "initial commit"
(now I edit 10 files and accidentally delete some files that I'm not aware of)

How do I now get the accidentally deleted files back from the repository without losing local changes made to 10 files?

I've tried using: "git checkout HEAD ." but my local changes after last commit will be lost.

I've tried using: "git pull ." but the deleted files are not restored.

So I'm looking for an "svn update" equivalent command that would semantically do this: "Get the latest version of all files from the repository and merge them with any local changes I've made to files."

I know a suitable command is available and I'm just a moron who can't read the manual correctly but help me out anyway :P

  Regards,
     Mikko
Howard Miller· Dec 1, 2009, 09:45 UTC · re: Mikko Oksalahti · lore

Re: Newbie "svn update" question

2009/12/1 Mikko Oksalahti <mikko@azila.fi>:
Show 33 quoted lines
> Hi,
>
> I just started using git for my personal projects at home. Basic usage seems
> pretty straight-forward as well as setting up everything. However, I have a
> simple question about how do I mimic an "svn update" command on a locally
> created repository. Here's what I do:
>
> some_existing_project_dir> git init
> some_existing_project_dir> git add .
>
> (about 1000 files added...)
>
> some_existing_project_dir> git commit -a -m "initial commit"
>
> (now I edit 10 files and accidentally delete some files that I'm not aware of)
>
> How do I now get the accidentally deleted files back from the repository without
> losing local changes made to 10 files?
>
> I've tried using: "git checkout HEAD ." but my local changes after last commit
> will be lost.
>
> I've tried using: "git pull ." but the deleted files are not restored.
>
> So I'm looking for an "svn update" equivalent command that would semantically do
> this: "Get the latest version of all files from the repository and merge them
> with any local changes I've made to files."
>
> I know a suitable command is available and I'm just a moron who can't read the
> manual correctly but help me out anyway :P
>
>  Regards,
>     Mikko

'git status' should show you what files you have deleted. 'git checkout filename' should get them back. I can't think of a way of recovering every file you have just deleted although - I suspect it might be tricky. Thinks like 'git pull' only apply to remote repositories and you don't have one of those. You're not thinking of it the right way (yet) :-)

Howard
Mikko Oksalahti· Dec 1, 2009, 12:00 UTC · re: Howard Miller · lore

Re: Newbie

Howard Miller <howardsmiller <at> googlemail.com> writes:
> 
> 2009/12/1 Mikko Oksalahti <mikko <at> azila.fi>:
> > How do I now get the accidentally deleted files back from the repository 
without
Show 10 quoted lines
> > losing local changes made to 10 files?
> 
> 'git status' should show you what files you have deleted.  'git
> checkout filename' should get them back. I can't think of a way of
> recovering every file you have just deleted although - I suspect it
> might be tricky. Thinks like 'git pull' only apply to remote
> repositories and you don't have one of those. 
> 
> Howard
> 

Ok. That helps. I just assumed the 'git pull' would work same way on local and remote repositories but I guess not then...

> ....You're not thinking of it the right way (yet) 
I hate when you say that :P
  /Mikko
Tay Ray Chuan· Dec 1, 2009, 09:49 UTC · re: Mikko Oksalahti · lore

Re: Newbie "svn update" question

Hi
On Tue, Dec 1, 2009 at 5:25 PM, Mikko Oksalahti <mikko@azila.fi> wrote:
Show 11 quoted lines
> How do I now get the accidentally deleted files back from the repository without
> losing local changes made to 10 files?
>
> I've tried using: "git checkout HEAD ." but my local changes after last commit
> will be lost.
>
> I've tried using: "git pull ." but the deleted files are not restored.
>
> So I'm looking for an "svn update" equivalent command that would semantically do
> this: "Get the latest version of all files from the repository and merge them
> with any local changes I've made to files."
Are you looking for a command that
  "Restore deleted files, without reverting local changes",
or
  "Get the latest version of all files from the repository and merge
them with any local changes I've made to files."?
I would suggest adding the changed files, then doing a checkout.
  git add changed.file1
  git add changed.file2
  git add -p #alternatively, select hunks/changes to add interactively
  git checkout HEAD #although using . (current directory) should give
the same result

Note that your changes have only been added to the index, and you need to commit them. The index/stage is a concept not in svn. See the user manual for more on this.

I also suspect you are still thinking in svn mode when you said getting the latest version from the repository. You already have a repository locally. It is more an issue of syncing your local repository with the one that you're following. Unlike svn, every time you commit, your local repository is updated, not the remote one, and vice-versa.

-- 
Cheers,
Ray Chuan

← back to recent threads