你怎么只推动你的一些本地git提交? [英] how do you push only some of your local git commits?
问题描述
这不起作用:
git checkout HEAD〜3#将头部设置为3次提交前
git push #attempt从该头开始推送
推动所有5个本地提交。
我想我可以做git reset来实际撤消我的提交,然后是git stash然后git push - 但我已经提交了写入的提交消息并组织了文件我不想重做它们。
我的感觉是,一些传递给推送或重置的标志将起作用。
如果有帮助,这里是我的git配置
[ramanujan: 〜/ myrepo / .git] $ cat config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[远程起源]
url = ssh://server/git/myrepo.git
fetch = + refs / heads / *:refs / remotes / origin / *
[branch'master ]
remote = origin
merge = refs / heads / master
<$ c如果你使用的是git-svn:<$ c> $ git push origin master〜3:master
/ p>
$ git svn dcommit master〜3
在git-svn的情况下,您也可以使用HEAD〜3,因为它期望提交。在直接混帐的情况下,您需要使用分支名称,因为HEAD在refspec中没有正确评估。
您也可以采取更长的方法: / p>
$ git checkout -b tocommit HEAD〜3
$ git push origin tocommit:master
如果您习惯使用这种类型的工作流程,则应考虑在单独的分支中完成您的工作。然后你可以这样做:
$ git checkout master
$ git merge working〜3
$ git push origin master:master
请注意,origin master:master设置。
Suppose I have 5 local commits. I want to push only 2 of them to a centralized repo (using an SVN-style workflow). How do I do this?
This did not work:
git checkout HEAD~3 #set head to three commits ago
git push #attempt push from that head
That ends up pushing all 5 local commits.
I suppose I could do git reset to actually undo my commits, followed by git stash and then git push -- but I've already got commit messages written and files organized and I don't want to redo them.
My feeling is that some flag passed to push or reset would work.
If it helps, here's my git config
[ramanujan:~/myrepo/.git]$cat config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = ssh://server/git/myrepo.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
Assuming your commits are on the master branch and you want to push them to the remote master branch:
$ git push origin master~3:master
If you were using git-svn:
$ git svn dcommit master~3
In the case of git-svn, you could also use HEAD~3, since it is expecting a commit. In the case of straight git, you need to use the branch name because HEAD isn't evaluated properly in the refspec.
You could also take a longer approach of:
$ git checkout -b tocommit HEAD~3
$ git push origin tocommit:master
If you are making a habit of this type of work flow, you should consider doing your work in a separate branch. Then you could do something like:
$ git checkout master
$ git merge working~3
$ git push origin master:master
Note that the "origin master:master" part is probably optional for your setup.
这篇关于你怎么只推动你的一些本地git提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!