簡體   English   中英

將主站重新設置為功能分支

[英]Rebase master to feature branch

您好,我創建了一個新的存儲庫,將其克隆,忘記創建功能分支並開始在master分支中工作。 現在我意識到了,我想解決這個問題。 我還沒有做任何事情。 我現在的目標是將當前更改“轉移”到功能分支,使母版完全干凈(處於回購被克隆的狀態)。 有沒有非侵入性的方法來實現這一目標? 謝謝!

盡你所能,我藏起來你的變化

git stash

然后創建新分支

git checkout <your new branch name>

並應用您的更改

git stash apply
git add . // to add all the changed files to index (so that git 'become aware' of these files
git stash // to "put aside" all the changes that git is aware of
git status // should be empty, since you haven't committed you're in sync with master
git checkout -b  myfeaturebranch // create a branch, after this command you're on feature branch
git stash apply  // apply all the stashed (putted aside) changed to feature branch

如果您尚未提交任何內容,請通過master進行:

git checkout -b <my-new-branch>
git add *
git commit -m "updated"

直接的方式是這樣的

$ git checkout cool-feature
$ git rebase master

然后在您希望將功能分支合並到master時將其合並到master中:

$ git checkout master
$ git merge cool-feature

您可以使用git rev-parsegit update-ref來簡單地更改本地名稱,並刪除分支以保護罪行。

也就是說,獲取遠程起源分支提示的sha1(可能是起源/主節點)。

記住要重命名的當前分支的名稱git rev-parse --symbolic-full-name HEAD (可能是refs / heads / master)

git checkout -b <newname>

git update-ref <oldbranchrefname> <remote_tip>

現在,您應該將用作當前分支,並將以前的分支名稱重置回獲取的提示。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM