0

我在 master 分支中有 3 个提交:

  • 第三

  • 第二

  • 第一的

我需要获得第一次提交(我是使用 checkout 命令完成的),对其进行编辑并将提交推送到远程仓库。我已经做了以下步骤:

  1. git checkout(我的分支是“(从...分离)”)
  2. 一些版本
  3. git commit --amend

但是我怎样才能将我的提交推送到主分支呢?提前致谢。

4

4 回答 4

0

只是使用git push origin master. 确保你在master分支。

于 2013-11-07T10:18:26.333 回答
0
git checkout master

接着 git merge 'other_branch_name'

于 2013-11-07T10:26:53.943 回答
0

使用变基:

git rebase first^ --interactive 

然后在编辑器中替换pickedit,然后保存并运行。您将能够编辑内容,然后提交git commit --amend

然后,推送您的私人仓库所在的服务器:

git push origin master -f

-f是必需的,意思是“强制”:因为重新发布发布的内容通常是一个坏主意(这就是为什么我将私人回购加粗:如果存储库被其他人使用,请不要这样做,或者先警告他们他们将不得不这样做变基或重置他们的本地仓库)

于 2013-11-07T10:28:36.883 回答
0

It seems you haven't been working on master branch but on detached HEAD. It is a bit dangerous since you can lose commits until there is a reference to them (branch, tag). So use:

git branch temp

Then you can put your commits to local master:

git checkout master
git merge temp

The temporary branch is useless anymore, so delete it:

git branch -d temp

Your commits are on local master now and you can push them.

(You could also make a notice of the SHA1 of the detached HEAD, skip git branch commands I mentioned and use the git merge with that SHA1 instead of a branch name. However, I find the way using branch more git-aware.)

于 2013-11-07T10:38:26.403 回答