簡體   English   中英

當您的項目文件夾中包含以前的.git文件時,如何設置bitbucket?

[英]How to set up bitbucket when you have a project folder with previous .git files?

我最近在機器上重新安裝了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.

您必須先將它們添加到這些文件中,然后再提交並推送它們:

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

但是,從文件名中我猜它們是臨時文件,您最好刪除並忽略它們(在.gitignore ):

*~

另外,就像@MikkoOhtamaa所評論的那樣,您可以只創建一個新的存儲庫:

如果文件相同,則從頭開始重新創建一個新的存儲庫。 那是最簡單的解決方案。 – Mikko Ohtamaa 23小時前

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM