将分支复制到主分支并推送到远程

  • 本文关键字:分支 复制 git
  • 更新时间 :
  • 英文 :


在我的master分支上,我有很多不需要的文件:

good_file1
good_file2
bad_file1
bad_file2
good_file3

在我的temp分支上,我只有很好的归档:

good_file1
good_fil2
good_file3

我希望master分支与temp分支完全相同。

我所做的是:

git checkout master
git reset --hard new15
git push origin master

我正在得到

! [rejected]          master -> master (non-fast-forward)
error: failed to push some refs to ''
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

但是现在,当我做git pull我正在拉bad_files。另外,我不能使用force,因为分支受到保护。我该怎么办?

如果你使用的是 github,你应该发出一个拉取请求,但如果不是:

您希望将分支合并到主分支中。

git checkout master
git pull origin master
git merge temp
git push origin master

退房 https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging

最新更新