【问题标题】:Git, Initial commit with changesGit,带有更改的初始提交
【发布时间】:2019-02-18 07:45:42
【问题描述】:

在服务器中...

$ git --version
git version 1.8.3.1

在客户端

λ git --version
git version 2.17.1.windows.2

我有一个 git 文件夹(在 Windows 中),其中包含即将添加的新文件

我初始化了我的文件夹

C:\Users\IT.Developer\MigrationProject
λ git init
Initialized empty Git repository in C:/Users/IT.Developer/MigrationProject/.git/

C:\Users\IT.Developer\MigrationProject (master -> origin)
λ ls -al
total 21
drwxr-xr-x 1 IT.Developer 1049089 0 Sep 13 08:58 ./
drwxr-xr-x 1 IT.Developer 1049089 0 Sep 13 08:57 ../
drwxr-xr-x 1 IT.Developer 1049089 0 Sep 13 08:58 .git/
-rw-r--r-- 1 IT.Developer 1049089 7 Sep 13 08:58 NewFile2BeCommitted.txt

> Blockquote

C:\Users\IT.Developer\MigrationProject (master -> origin)

我添加了文件(仅一个用于 porpouse 示例)!

λ git add .

C:\Users\IT.Developer\MigrationProject (master -> origin)
λ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   NewFile2BeCommitted.txt


C:\Users\IT.Developer\MigrationProject (master -> origin)

现在我提交了....

λ git commit -m "Upload 2, test"
[master (root-commit) cf6cb7f] Upload 2, test
 Committer: Developer (Vertical Health Internal) <IT.Developer@INTERNAL.NET>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:

    git config --global --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 file changed, 1 insertion(+)
 create mode 100644 NewFile2BeCommitted.txt

C:\Users\IT.Developer\MigrationProject (master -> origin)

我的下一步是添加到远程服务器...

λ git remote add origin git@192.168.5.200:/srv/git/project.git

C:\Users\IT.Developer\MigrationProject (master -> origin)

这是我的痛苦......

λ git push origin master
Enter passphrase for key '/c/Users/IT.Developer/.ssh/id_rsa':
To 192.168.5.200:/srv/git/project.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@192.168.5.200:/srv/git/project.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

C:\Users\IT.Developer\MigrationProject (master -> origin)

我试图解决(跳转)不一致

λ git stash
No local changes to save

C:\Users\IT.Developer\MigrationProject (master -> origin)

我试图拉动

λ git pull
Enter passphrase for key '/c/Users/IT.Developer/.ssh/id_rsa':
warning: no common commits
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From 192.168.5.200:/srv/git/project
 * [new branch]      master     -> origin/master
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> master


C:\Users\IT.Developer\MigrationProject (master -> origin)

我再次尝试拉动

λ git pull origin master
Enter passphrase for key '/c/Users/IT.Developer/.ssh/id_rsa':
From 192.168.5.200:/srv/git/project
 * branch            master     -> FETCH_HEAD
fatal: refusing to merge unrelated histories

C:\Users\IT.Developer\MigrationProject (master -> origin)

但是,我又不能

如何解决?

【问题讨论】:

  • 您在维护自己的私有 Git 服务器吗?第一条错误消息似乎是说 repo 上已经有一个或多个提交。如果是这样,那么也许您应该克隆存储库。如果您使用的是 GitHub 或 Bitbucket 之类的东西,那么您应该仔细按照他们的说明开始使用。
  • 当你拉它不知道从哪里拉时,执行 git branch --set-upstream-to=origin/master master 然后执行 git pull 看看是否有效
  • 是的,我正在测试它是否可以从另一个用户那里工作。

标签: git git-push git-pull


【解决方案1】:

看起来您离线启动了项目,没有克隆存储库。第一个错误似乎是因为远程仓库已经在您尝试推送的分支中提交了。

要么首先克隆 repo,然后添加你的提交,要么你可以通过传递 --allow-unrelated-histories 选项。

 git pull origin <branch name> --allow-unrelated-histories

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-20
    • 2014-08-02
    • 2014-07-12
    • 2012-10-13
    • 2015-10-01
    • 1970-01-01
    • 2012-09-16
    相关资源
    最近更新 更多