简体   繁体   English

Git简化历史记录

[英]Git Maintaining history Streamlined

I have taken a branch(Branch A) from Master and done some commits on the Branch A, in the meantime, some Commits are merged on Master from Another Branch B Problem is: I have to Push my commits and Merge to Master so which approach will be best : 我已经从Master取得了一个分支(分支A),并在分支A上做了一些提交,与此同时,一些Commit从另一个Branch B合并到Master上了。最好:

1)I Push My commits to remote Branch A, then checkout master, then take a pull and then merge the Branch A in master and Push the merged code in Master. 1)我推送我的提交到远程分支A,然后检出master,然后进行拉取,然后将Branch A合并到master中,然后将合并的代码推送到Master中。

2)I check out master and git pull with rebasing the master and then Checkout Branch A and Push my commits to Branch A and then Checkout Master and merge Branch A in Master and Push the Master. 2)我检出master和git pull并重新设置master,然后检出Branch A,然后将提交提交到Branch A,然后检出Master,然后将Branch A合并到Master中,然后推入Master。

Push branchA to remote: branchAbranchA远程:

$ git push origin branchA

Checkout to master , update master with remote master . 结帐到master ,更新masterremote master Pull branchA into master , then push to remote: branchA拉入master ,然后推送到remote:

$ git checkout master      # master branch
$ git pull origin master   # update local master history = remote master history

$ git pull origin branchA  # pull 'branchA' changes into 'master' branch  
$ git push origin master   # update remote master with branchA changes

You need neither, assuming that you are working in a pure git environment (ie, no "external" workflow management like Github's "pull requests" or something like that). 无需假设您在纯git环境中工作(即,无需像Github的“拉取请求”之类的“外部”工作流管理)。

Simply merge your branch locally, and then push those of the two that you want to have remote (ie, pushing branchA is only necessary if you want to keep that branch long-term, and also want to have it remotely viewable for posteriority). 只需在本地合并分支,然后将要远程的两个分支推送即可(即,仅当您希望长期保留该分支并且还希望远程查看该分支以实现branchA ,才需要推送branchA )。

git checkout master
git pull origin master    # just in case someone else changed it meanwhile...
git merge branchA
git push origin master branchA

Explanation: 说明:

First, you checkout master . 首先,您结帐master This means your local "current" branch is master , and the working directory represents its current file tree. 这意味着您本地的“当前”分支为master ,工作目录代表其当前文件树。

Next, you pull the master from origin . 接下来,从origin拉出master This is useful if someone else, meanwhile, committed something onto the remote master; 如果其他人同时将某些东西提交到远程主服务器上,这将很有用; it means that you're now up to date. 这意味着您现在处于最新状态。 If you know that nobody could have done that (because you're the only one working on it), then you can skip this step. 如果您知道没有人能做到这一点(因为您是唯一从事此工作的人),那么可以跳过此步骤。

Thirdly, you merge your branchA into your local master . 第三,将您的branchA合并到本地master I assume that you own branchA , that is, there is no chance that there could be a more recent branchA on origin , hence no further push/pull is necessary. 我假设您拥有branchA ,也就是说,没有机会在origin上有一个更新的branchA ,因此不需要进一步的推/拉操作。

Finally, you push both master and branchA back to origin . 最后,将masterbranchA都推回origin The remote (and your local) master will now contain the merge commit that includes all changes originating in branchA . 远程(和您本地的) master现在将包含合并提交,该提交包含源自branchA所有更改。 branchA will be unchanged and stick around for either historical purposes, or for further changes. branchA将保持不变,并且出于历史目的或进一步更改而保留。

On rebase vs. merge 在重设与合并

Some people never rebase, but always merge. 有些人从不变基,但总是合并。 Other people like to rebase. 其他人喜欢变本加厉。

You commented that you know about the difference, so I'll not write much. 您评论说,您知道其中的区别,所以我不会写太多。 But for this particular usecase (getting changes from a feature branch back into master ), merging is the correct operation, and there should not be a rebase involved. 但是对于这个特定的用例(从功能分支将更改返回到master ),合并是正确的操作,并且不应该涉及任何rebase

If you were asking how to get changes from master back into branchA , then we would talk about whether you would use rebase or merge . 如果您询问如何将master更改返回到branchA那么我们将讨论您将使用rebase还是merge

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 git工作流程:维护功能提交的历史记录 - git workflow: maintaining a history of functional commits API版本控制同时保持git历史记录 - API Versioning while maintaining git history 在保持历史记录的同时将git目录上移一个文件夹 - Move git directory a folder up while maintaining history 如何在保持历史记录的同时将git repo推送到现有的SVN repo? - How to push a git repo to an existing SVN repo while maintaining history? 多开发人员Git工作流程,保持干净的历史记录 - A multi-developer Git workflow, maintaining a clean history 如何将 git 存储库合并到维护提交历史记录的父存储库中? - How to merge a git repo into a parent repo maintaining commit history? 将 git 存储库与另一个存储库的子目录合并,保持历史记录 - Merge git repo with another repo's subdirectory, maintaining history 如何在保留尽可能多的历史记录的同时从 git 的历史记录中清除一个词? - How can I purge a word from git's history while maintaining as much history as possible? 如何在维护历史记录的同时将单个目录从git存储库移动到新存储库? - How can I move a single directory from a git repository to a new repository whilst maintaining the history? 将目录从现有的Git存储库移至新的存储库,以保持历史记录并缩小大小 - Move directory from existing Git repository to a new repository maintaining history and minizing size
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM