git push 单个文件到远程跟踪分支

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6389317/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 11:12:13  来源:igfitidea点击:

git push single file to a remote tracking branch

gitgithub

提问by Rubyalto

Folks,

各位,

This is my use case: I have 3 branches, all three are remote tracking branches.

这是我的用例:我有 3 个分支,所有三个都是远程跟踪分支。

git branch
  release-alpha
* release-allUS
  master

Now I added a new file in release-allUS branch, I made a commit by doing this:

现在我在 release-allUS 分支中添加了一个新文件,我通过这样做进行了提交:

 git add filter_driver.rb 
 git commit -m "driver code"

Now I want to push only this file to the remote release-allUS branch, How do I do that? Thanks a lot for any feedback.

现在我只想将此文件推送到远程 release-allUS 分支,我该怎么做?非常感谢您的任何反馈。

回答by vcsjones

Since all that you committed locally was that one file, a git pushto your remote will work. Push will only push what has been committed locally.

由于您在本地提交的所有文件都是该文件,因此git push您的远程文件将起作用。推送只会推送本地提交的内容。

git push origin release-allUS

As manojlds pointed out in the comments, this will only work if nothing else has been stages and there are no other unpushed local commits. If that is the case, you are are probably best creating a new tracking branch from the remote, cherry picking the local commit into the new branch, pushing to the remote, then rebasing the original tracking branch.

正如 manojlds 在评论中指出的那样,这只有在没有其他任何阶段并且没有其他未推送的本地提交时才有效。如果是这种情况,您可能最好从远程创建一个新的跟踪分支,将本地提交挑选到新分支中,推送到远程,然后重新定位原始跟踪分支。

回答by hellatan

i know you can push to a certain branch this way:

我知道你可以通过这种方式推送到某个分支:

git push origin <branch>

I just took a quick look at the git push --helpand it doesn't seem to say anything about sending a single file commit to a branch.

我只是快速浏览了一下,git push --help它似乎没有说明将单个文件提交发送到分支。

maybe one work around to this would be to have an integrationbranch that you never touch except when you want to push commits around. if you're in your integrationbranch, you could do a git cherry-pick <commit>from your other branch bringing over only what was in that commit to the integrationand then do a git push origin integration.

也许解决这个问题的一个方法是拥有一个integration你永远不会触及的分支,除非你想推动提交。如果你在你的是integration分支,你可以做一个git cherry-pick <commit>从您的其他分支带来了只什么在提交到integration,然后做了git push origin integration