Git推送到远程问题

时间:2016-06-10 05:21:31

标签: git

如何将单个提交推送到回购?特别是在388c85上面的那个。 当我尝试推送到远程仓库时,它会选择下面的两个提交。

Git Log

commit 388c85ccb56164c6f0c91584aa9251b87acc7f89
Author: test <test@gmail.com>
Date:   Mon Jun 6 16:38:50 2016 -0400

Login Page updates

commit 3d4b4da976bfefff4a18bfbcbfb9bdaa35d7c991
Author: test <test@gmail.com>
Date:   Mon Jun 6 13:09:19 2016 -0400

initial commit this mostly include user interface updates

3 个答案:

答案 0 :(得分:2)

据我了解,你有这样的事情:

A -- B -- C -- D -- E
     \               \- master
      \- origin/master

并且您希望将提交E添加到远程存储库,但您不希望CD

然后你应该挑选E

git checkout B # use for instance the sha1 of this commit
git checkout -B BES-22 # it creates the branch BES-22 locally and puts you on it
git cherry-pick E

此时你有:

A -- B -- C -- D -- E
      \ -- E'       \-master
       \    \- BES-22
        \- origin/master

所以你可以推动:

git push origin BES-22

特别要注意:

  • 由于提交在Git中是不可变的,cherry-pick创建了一个全新的提交E'

  • 如果您有错误error: unable to push to unqualified destination: BES-22 The destination refspec neither matches an existing ref on the remote nor begins with refs/, and we are unable to guess a prefix based on the source ref.,则或多或少意味着遥控器上不存在分支BES-22。使用git push origin <branch>代替git push origin <sha1>:<unexisting remote branch>应该修复它

答案 1 :(得分:0)

尝试以下命令

git push <remotename> <commit SHA>:<remotebranchname>

实施例

git push origin 388c85ccb56164c6f0c91584aa9251b87acc7f89:master

在上述情况下,master是您要推送的分支。

答案 2 :(得分:0)

git总是将所有提交推送到HEAD(给定提交哈希)。因此,在git push推送HEAD之前的所有提交时,即使您执行git push origin 388c85ccb56164c6f0c91584aa9251b87acc7f89:master,也会将所有提交推送到388c85ccb56164c6f0c91584aa9251b87acc7f89。您可以做的一件事是重新排序您的提交历史记录,以便历史记录如下所示:

commit 3d4b4da976bfefff4a18bfbcbfb9bdaa35d7c991
Author: test <test@gmail.com>
Date:   Mon Jun 6 13:09:19 2016 -0400

initial commit this mostly include user interface updates

commit 388c85ccb56164c6f0c91584aa9251b87acc7f89
Author: test <test@gmail.com>
Date:   Mon Jun 6 16:38:50 2016 -0400

Login Page updates

现在,如果您执行git push origin 388c85ccb56164c6f0c91584aa9251b87acc7f89:master,则仅推送388c85ccb56164c6f0c91584aa9251b87acc7f89提交,而不是3d4b4da976bfefff4a18bfbcbfb9bdaa35d7c991

为了重新订购git提交,您可以参考:https://stackoverflow.com/a/16203754/3878940https://stackoverflow.com/a/4981173/3878940