【问题标题】:How to set up bitbucket when you have a project folder with previous .git files?当您的项目文件夹包含以前的 .git 文件时,如何设置 bitbucket?
【发布时间】:2016-01-01 02:22:15
【问题描述】:

我最近在我的机器上重新安装了 Ubuntu,并备份了所有文件和文件夹。我正在使用 PyCharm 将本地文件与 bitbucket 上的存储库同步回来。我已经看过很多关于如何为新存储库执行此操作的教程,但是如果您的项目已经存在并且您在项目中有现有的 .git 文件,我还没有看到有关如何执行此操作的教程。

我已经下载了 bitbucket 插件,设置了我的遥控器,并测试了连接,但是当我尝试推送文件时,我不断收到此错误:

Commit failed with error:
On branch master
Changes not staged for commit:
    modified:   Detection-alf/loadTrainingImages.py~
    modified:   automated-detection-for-alf/bibsmart_auto_detector.py~
    modified:   automated-detection-for-alf/bibsmart_verify_csv.py~

这就是我执行 git push 得到的结果

alfredo@alfpc-ubuntu:~/Dropbox/Alfredo1/Caffe$ git push
Username for 'https://bitbucket.org': alfredox10
Password for 'https://alfredox10@bitbucket.org': 
To https://bitbucket.org/alfredox10/bibsmart_detection
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://bitbucket.org/alfredox10/bibsmart_detection'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

我做了 git pull 并再次尝试。

alfredo@alfpc-ubuntu:~/Dropbox/Alfredo1/Caffe$ git pull
Cannot pull with rebase: You have unstaged changes.
Please commit or stash them.

但我不得不隐藏更改。

alfredo@alfpc-ubuntu:~/Dropbox/Alfredo1/Caffe$ git stash
Saved working directory and index state WIP on master: df3e5e0 terminal git test commit
HEAD is now at df3e5e0 terminal git test commit

最后我做了 git pull,让我的本地文件和服务器上的一样。

alfredo@alfpc-ubuntu:~/Dropbox/Alfredo1/Caffe$ git pull
Username for 'https://bitbucket.org': alfredox10
Password for 'https://alfredox10@bitbucket.org': 
From https://bitbucket.org/alfredox10/bibsmart_detection
 * branch            master     -> FETCH_HEAD
Auto packing the repository for optimum performance. You may also
run "git gc" manually. See "git help gc" for more information.
Counting objects: 159251, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (159214/159214), done.
Writing objects: 100% (159251/159251), done.
Total 159251 (delta 15072), reused 0 (delta 0)
Removing duplicate objects: 100% (256/256), done.
fatal: Needed a single revision
invalid upstream 24c9aac9a2eccf4313835cf89f7ece050e049d46

我又做了一次 git push,我现在仍然得到这个。

alfredo@alfpc-ubuntu:~/Dropbox/Alfredo1/Caffe$ git push
Username for 'https://bitbucket.org': alfredox10
Password for 'https://alfredox10@bitbucket.org': 
To https://bitbucket.org/alfredox10/bibsmart_detection
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://bitbucket.org/alfredox10/bibsmart_detection'
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.

【问题讨论】:

  • 我只建议使用 Bitbucket 在通过网络创建新项目时提供的复制粘贴说明从命令行执行此操作。
  • 我做到了,还是不走运。
  • 你推送的仓库不为空。
  • 如果文件相同,只需从头开始重新创建一个新的存储库。这是最简单的解决方案。
  • 是的,这就是最终的工作,谢谢伙计!

标签: git github version-control bitbucket pycharm


【解决方案1】:

您必须先添加这些文件,然后提交并推送它们:

git add .
git commit -m 'Your commit message'
git push

但是,从文件名我猜它们是临时文件,你最好删除并忽略它们(.gitignore):

*~

另外,就像@MikkoOhtamaa 评论的那样,您可以创建一个新的存储库:

如果文件相同,只需从头开始重新创建一个新存储库。这是最简单的解决方案。 – Mikko Ohtamaa 23 小时前

【讨论】:

  • 我修改了帖子,尝试了您告诉我的一些内容,以及我在网上找到的其他内容。
  • @alfredox 好的,我们一步一步来:git status 现在的输出是什么?
  • > 在分支 master > 未为提交暂存的更改:>(使用“git add ...”更新将提交的内容)>(使用“git checkout -- ..." 丢弃工作目录中的更改)> > 修改:.idea/workspace.xml > > 没有更改添加到提交(使用“git add”和/或“git commit -a”)> alfredo@alfpc-ubuntu :~/Dropbox/Alfredo1/Caffe$
  • @alfredox 好的,现在就这样做git add . -A,然后是git commit -m 'Saving work'(或一些相关消息)。然后再次给我发送git status 输出或git commit/add 的输出(如果它们失败了)。
  • @alfredox 查看编辑。标记答案将不胜感激。 :) 谢谢!!
猜你喜欢
  • 2021-11-15
  • 2010-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-06
  • 2014-07-04
相关资源
最近更新 更多