I have a remote that is the same, or similar, to the rails project in my current directory. To sync the two, I do
git init
git remote add origin blah@blah
git pull
The problem is that some of the files I had in my working copy were added (ie not in the remote), so when I do
git status
it should show a bunch of untracked 开发者_如何学编程files. Instead I see the files from the repo that are out of date.
Why didn't it ask me to resolve conflicts in these files? And where are my old files?The merge implicit in "git pull" must have overwritten local files that were not committed.
I would suggest this sequence:
git init
git add .
git commit -m"local"
git remote add origin blah@blah
git fetch origin
At this point, observe the repository with "gitk --all"
Merge with
git merge remotes/origin/master
This should let you know of conflicts, if any. And local files won't be overwritten.
What if, after the commands you did above, you try doing this?
git checkout blah
git pull origin blah
I'm still learning git, so I'm not positive, but just a guess. (Might need to replace blah
with blah@blah
in the commands above too.)
If you have a local repo (with its working directory), you shouldn't need to 'git init
' anything.
git remote add origin blah@blah
git pull
should be enough.
If you have made a git init
, that should be in an empty repository, where you then imported the master content of 'origin
'.
I didn't have a local repo, just the local files.
Then you need to add them first (see r-mercado's answer).
From the git pull
man page:
Warning: Running
git pull
(actually, the underlyinggit merge
) with uncommitted changes is discouraged: while possible, it leaves you in a state that is hard to back out of in the case of a conflict.
精彩评论