Newbie "svn update" question
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 initsome_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
2009/12/1 Mikko Oksalahti <[email protected]>:
Quoted 28 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 initsome_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."
Quoted 5 lines
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
Re: Newbie
Quoted 3 lines · Howard Miller <howardsmiller <at> googlemail.com> writes:
2009/12/1 Mikko Oksalahti <mikko <at> azila.fi>:
Quoted 1 line
How do I now get the accidentally deleted files back from the repository
without
Quoted 10 lines
Quoted 1 line
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...
Quoted 1 line
....You're not thinking of it the right way (yet)
I hate when you say that :P
/Mikko
Hi
Quoted 11 lines · Mikko Oksalahti
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.
Signature · 2 lines
Cheers, Ray Chuan