简体   繁体   中英

How to git merge changes from main branch to orphan branch without adding to orphan's history?

I have a git repository for my phd dissertation (in latex). The university policies does not allow me to share the background review chapter of my dissertation with my research adviser, I am free to share and get opinion for other chapters.

To share the repository with my advisor I created an orphan branch (noRevBranch) with the required chapter removed and pushed and tracked this branch to a new repository on github. I can share this with his and he can not access the removed chapter because there is no history here.

The question is how do I merge any changes I make to the master branch in the future to the noRevBranch without also appending the master branch history to the new merge commit?

You can leave the structure as its right now.
What you can do is to use git cherry-pick <range of commits> to commit all the new commits to the "orphan" branch.

git cherry-pick <SHA-1>...<SHA-1>

Apply the change introduced by the commit at the tip of the master branch and create a new commit(s) with this change.

The syntax of the ... is a commit range. grab all commits from start (exclude) to the last one.

在此输入图像描述


Read out the full git cherry-pick documentation for all the options you can use

I think you're doing it backwards. You need to think of noRevBranch as master and do all your commits on that branch. If don't push the branch with the background chapter (revBranch) to Github, you can rebase it whenever you need to. History of this branch will never be shared with your adviser because it's a local branch stored only on your computer, and since it was never merged into noRevBranch your advisor won't have access to its history either. But the key is that you're doing your commits (that do not affect the background chapter) on noRevBranch, since this will allow you to easily pull them into revBranch by rebasing.


EDIT in response to jlanza:

If I was starting this from scratch, I would do it like this:

  • Make master your public branch. Commit all your "public" work so far to this branch. Never commit any "private" work to this branch.
  • Make a new private branch based on master. We'll call it private . git checkout -b private . Commit anything that you don't want to share publicly to this branch.
  • Whenever you commit work that you want to share publicly, commit that work to master . You can push this branch to wherever your repo is hosted whenever you want. git push origin master:refs/heads/master .
  • Whenever you commit work that you don't want to share publicly, commit that work to private . Don't push this branch to any public repositories.
  • You can keep private up-to-date with master either by merging or re-basing. Something like git checkout private && git merge master .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM