1

I believe git, somehow, was uninstalled during an update of OS X. I have reinstalled git and I want to re-sync my local development folders to the appropriate github repos but am not sure how.

I have since created a new repo so my github account is linked properly, but I don't know how to link the existing stuff.

For example, say one project is located at:

/users/stephen/development/cs

and it's corresponding github SSH location is at:

git@github.com:stephen/cs.git

How do I get these synced back up?

4

3 回答 3

1

When you say that "git was somehow uninstalled", I assume you mean you cannot use the command git and you get -bash: git: command not found error. So the following should help.

Is git installed?

The first thing to do is type which git and that will tell you if its included in your path. If nothing is prints, then you know thats your first problem:

  1. It's not installed, or
  2. It is installed, but not included in your $PATH.

The solution to these problems, obviously, is install it or find it on your system. Typically on Mac OSX, it is found in /usr/bin/git. Add it to your $PATH like so:

export PATH=/usr/bin/:$PATH

in your .bashrc or .bash_profile (substitute /user/bin with the directory where you find git. )

Does the git repository still exists?

Now, check that the is repo didn't get destroyed. Most likely, it did not.

$ cd project/
$ ls -la
drwxr-xr-x  3 user  staff  102 May 24 18:31 .
drwxr-xr-x  6 user  staff  204 May 24 18:31 ..
drwxr-xr-x  9 user  staff  306 May 24 18:31 .git
-rw-r--r--  1 user  staff  119 May 24 18:34 README.md

The presence of the .git directory means it still exists, therefore finding/installing git is your only problem. As soon as you fix that problem, you should be able to use git exactly how you used to.

However, if the .git file is gone (highly unlikely), there are several things you can do.

  1. If you know your directory was in a clean state (all committed changes) and pushed to github before your loss, you can just delete the directory on your local machine and pull in a new fresh copy of the repo (easiest).
  2. If you know your repo was clean, but NOT pushed to github OR you had a dirty directory (with changes not committed), you are in a bad spot. However, it is not impossible to regain your repo to its original state. Without knowing your repo directory structure, I can't go into too much detail. But the following should work for most cases:
    1. Initialize a new repo in the project directory.
    2. Add all files and commit.
    3. Add the remote repository
    4. Pull down the repo to merge them together.
    5. Resolve conflicts.

Good luck :)

于 2012-05-25T01:34:09.803 回答
0

我认为即使 git 被卸载,repo 也不会失去它的身份。你git status在那个 repo 上尝试过命令吗?它说什么?此外,我会git init在备份后尝试添加遥控器。

于 2012-05-24T22:08:00.757 回答
0

Git 存储库只是文件的集合,独立于 Git 工具本身。卸载 Git 不会删除存储库,因此您的旧来源可能仍然存在。

cd /users/stephen/development/cs
git remote -v

如果您看到旧的原点,请将其指向新位置:

git remote set-url origin git@github.com:stephen/cs.git
git fetch origin

如果您没有看到您的旧来源,请添加它...

git remote add -f origin git@github.com:stephen/cs.git

...并为现有的本地分支机构设置跟踪器:

git branch --set-upstream master origin/master
git branch --set-upstream another-local-branch origin/a-remote-branch-to-be-tracked
etc.
于 2012-05-24T22:31:11.237 回答