如何将当前工作分支移动到git中的主分支 [英] How to move the current working branch to master branch in git

查看:124
本文介绍了如何将当前工作分支移动到git中的主分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个项目包含更多的分支机构。主分店还没有合并很久。所以我想用最新的代码切换到master。



你能给我一些必要的命令和步骤吗?

我正在一个有不同分支的项目中工作。最新的变化是在除了主人以外的一些分支。现在我的要求是:有没有办法将当前工作分支移到master而不与master进行合并,以避免冲突?

解决方案

如果你想在 master 中具有与 other_branch 完全相同的文件状态并保存历史记录 - 请执行下一步(它比 reset ):

  git checkout master 
git checkout other_branch。

(含期间)

other_branch 完整复制到当前( master ):
然后进行常规提交。

<$ p $

$ b复制other_branch到主工作树 git add --all
git commit -m

注意,来自 other_branch 的未跟踪(未编入索引)的文件(目录)将保留,如果它们未被master记录。要删除那些未跟踪的文件(目录):

  git clean -fd 
pre>

请参阅如何从当前Git工作中删除本地(未跟踪的)文件树?获取更多详情


I have currently one of the project it contain more branches. master branch not yet merger long time. So i want switched to master with latest code.

Can you please give me necessary commands and steps.

Let me re-frame my question.

I am working in a project with different branches. The latest changes were in some branch other than master. Now my requirement is: is there a way to move the current working branch to master without merging it with master, to avoid conflicts?

解决方案

If you want to have in master exactly the same files state as in other_branch and save history - do next (it is softer than reset):

git checkout master
git checkout other_branch .

(with period)

This will make full copy of other_branch to current (master): Then make regular commit.

git add --all
git commit -m "* copy other_branch to master working tree"

Note, untracked (unindexed) files (directories) from other_branch will remain, if they are not tracked by master. To remove those untracked files (directories):

git clean -fd

See How to remove local (untracked) files from the current Git working tree? for more details

这篇关于如何将当前工作分支移动到git中的主分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆