简体   繁体   English

如何在不添加Remote的情况下将提交推送到git存储库?

[英]How to push commit to git repository without adding Remote?

I have some repository, like 我有一些存储库,例如 https://nickname@bitbucket.org/nickname/repo-name.git . https://nickname@bitbucket.org/nickname/repo-name.git I need to push some data to this repo, using Java. 我需要使用Java将一些数据推送到此仓库中。

So, basically I want to do these steps: 因此,基本上我想执行以下步骤:

  1. Create temporary directory ( tmp_path == /temp/tmp/dir ) 创建临时目录( tmp_path == / temp / tmp / dir
  2. cd tmp_path cd tmp_path
  3. git init git初始化
  4. git remote add origin https://nickname@bitbucket.org/nickname/repo-name.git git remote add origin https://nickname@bitbucket.org/nickname/repo-name.git
  5. create temp file with needed data ( filanme == tmpfile.txt ) 使用所需数据创建临时文件( filanme == tmpfile.txt
  6. git add filename git添加文件名
  7. git commit --message="adding tmp file" git commit --message =“添加tmp文件”
  8. git push origin tmp-branch git push origin tmp-branch

But there is one problem. 但是有一个问题。 I cannot make " cd " from Java. 无法从Java中制作“ cd ”。 So I need another solution. 所以我需要另一个解决方案。

Is there any way to push some data to repository without local git folder? 有没有办法将一些数据推送到没有本地git文件夹的存储库?

I'm not familiar with Java, so I can just give commands without cd . 我对Java不熟悉,因此我可以不使用cd给出命令。

git init /temp/tmp/dir
# create tmpfile.txt in /temp/tmp/dir
git --git-dir=/temp/tmp/dir/.git --work-tree=/temp/tmp/dir add tmpfile.txt
git --git-dir=/temp/tmp/dir/.git commit --message "adding tmp file"
# your question says without adding remote, so we skip "git remote add"
git --git-dir=/temp/tmp/dir/.git push https://nickname@bitbucket.org/nickname/repo-name.git HEAD:refs/heads/tmp-branch

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将文件从 web 应用程序(弹簧启动)提交到 git 远程存储库,而不首先将存储库克隆为本地? 这可能吗 - commit file from a web application (spring boot) into git remote repository without first cloning the repo as local? is this possible 使用 JGit 推送更改直到特定提交到远程存储库 - Push changes till particular commit to remote repository with JGit 使用JGit检索远程Gerrit提交日志,而不克隆存储库? - Retrieve remote Gerrit commit logs using JGit without cloning the repository? 我如何在Heroku Play Framework中安装New Relic而不将代理添加到我的git存储库中? - How can I install New Relic in Heroku Play Framework without adding the agent to my git repository? 如何将Android Studio项目推送到远程GitLab存储库 - How to push an Android Studio Project to a remote GitLab Repository 新的远程存储库Eclipse Git - New remote repository eclipse git 如何解决:504网关超时(git远程存储库上的传输异常) - How to Solve : 504 Gateway Timeout (Transport Exception on git remote Repository) 我们的git远程存储库未与本地存储库同步 - Our git remote repository is not synchronized with local repository 我已经在 git 上提交并推送了一个新的 feature_branch,但是在 github 上的中央存储库中提交/推送后,它没有显示该分支上的更改 - I've commited and pushed a new feature_branch on git but it doesn't show the changes on that branch after commit/push in central repository on github git推无拉 - Git push without pull
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM