【发布时间】:2020-11-22 23:21:45
【问题描述】:
对于我是唯一一个创建代码的个人项目,我有时会在两个不同的 IDE 之间切换。因此,源代码本地存储在两个不同的地方。我想对 Bitbucket 上的代码进行历史记录/备份。 Git 能解决这个问题吗?
我在目录source_code 中有foo.cpp。我不想将远程仓库中的所有内容复制到source_code。添加并提交foo.cpp 后,我尝试运行git push origin master 并给出错误
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://bitbucket.org/...'
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 pull origin master 但它出错了
error: Pulling is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.
在这种情况下,未合并到底意味着什么?我怎样才能具体找到问题所在的文件?我猜问题是我有同名的文件,但我只想从目录中跟踪一个特定的文件。如此简单的任务,我希望很容易。
当我做git status 时,它给了
You are currently rebasing branch 'master' on '930b2f7'.
(fix conflicts and then run "git rebase --continue")
(use "git rebase --skip" to skip this patch)
(use "git rebase --abort" to check out the original branch)
Unmerged paths:
(use "git restore --staged <file>..." to unstage)
(use "git add <file>..." to mark resolution)
both added: foo2.cpp
Bitbucket 的 foo2.cpp 版本是正确的,所以我删除了本地版本。然后我运行了 $ git restore --staged foo2.cpp,它起作用了。现在git pull origin master 工作。但是还是推不开。
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://bitbucket.org/...'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and 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)上的特定项目的正确术语?)
它还说(master|REBASE 2/3),我不知道它是什么意思。
【问题讨论】:
-
如果您仍在进行 rebase 操作,请运行
git rebase --continue以恢复 rebase。 -
另外,darn 确保您没有重新调整以前从 master 推送的提交。
-
你是什么意思你是“在两个IDE之间切换”本地存储在两个不同的地方?这是否意味着您在本地有两个 repo 副本,每个 IDE 一个?
-
问:“说我需要拉,但已经这样做了……” 答:这正是它的意思:你的遥控器与你的本地仓库没有正确同步:( LightCC 给出了一个很好的回复。如果您觉得有用,请务必“点赞”和“接受”。更重要的是:请务必阅读。请相应地调整您的git workflow。如果您有其他问题,请回复。
-
@LightCC 我的意思是我对大部分代码使用重量级 IDE,但有时更喜欢 Notepad++ 用于小型驱动程序/实验。 Notepad++ 创建的文件与 IDE 创建的文件位于不同的目录中。
标签: git bitbucket git-push git-pull