如果回购中已经存在另一个项目,如何将我的项目添加到远程回购?
How to add my project to remote repo, if in the repo another projects already exist?
我想将我的项目与其他项目一起添加到远程仓库。
我尝试执行下一个:
git init
git add --all
git commit -a -m 'first commit'
git remote add origin https://myrepo.git
git push origin master
并收到错误 'updates were rejected because the remote contains work that you do hint not have locally'。
我是用'git push -f origin master'加的,但是不是很聪明,因为我去掉了另一个项目
是否可以只添加和更新我的项目而不编辑其他项目?
在一个代码库中可以有两个独立的、不相关的分支。这可以按照答案 here.
完成
git checkout --orphan newbranch
git rm -rf .
<do work>
git add your files
git commit -m 'Initial commit'
这将允许您在 newbranch
中推送与您的其他项目无关的代码,比方说,在 master
分支中。
但是,我强烈建议您不要这样做,而是为您的两个不同项目创建两个单独的存储库。 Git 使得一个项目有一个 repo,而不是跟踪两个完整的独立项目。
如果一个项目依赖于另一个项目,您可以查看submodules。
另请注意,--orphan
选项 意味着 作为创建代码的选项,稍后将合并到主项目中的其他分支。以这种方式使用它,将是误用。
我想将我的项目与其他项目一起添加到远程仓库。
我尝试执行下一个:
git init
git add --all
git commit -a -m 'first commit'
git remote add origin https://myrepo.git
git push origin master
并收到错误 'updates were rejected because the remote contains work that you do hint not have locally'。
我是用'git push -f origin master'加的,但是不是很聪明,因为我去掉了另一个项目
是否可以只添加和更新我的项目而不编辑其他项目?
在一个代码库中可以有两个独立的、不相关的分支。这可以按照答案 here.
完成git checkout --orphan newbranch
git rm -rf .
<do work>
git add your files
git commit -m 'Initial commit'
这将允许您在 newbranch
中推送与您的其他项目无关的代码,比方说,在 master
分支中。
但是,我强烈建议您不要这样做,而是为您的两个不同项目创建两个单独的存储库。 Git 使得一个项目有一个 repo,而不是跟踪两个完整的独立项目。
如果一个项目依赖于另一个项目,您可以查看submodules。
另请注意,--orphan
选项 意味着 作为创建代码的选项,稍后将合并到主项目中的其他分支。以这种方式使用它,将是误用。