moving committed (but not pushed) changes to a new branch after pull

后端 未结 10 1413
灰色年华
灰色年华 2020-12-22 15:51

I\'ve done a fair bit of work (\"Your branch is ahead of \'origin/master\' by 37 commits.\") which really should have gone into its own branch rather than into master<

相关标签:
10条回答
  • 2020-12-22 16:21

    One more way assume branch1 - is branch with committed changes branch2 - is desirable branch

    git fetch && git checkout branch1
    git log
    

    select commit ids that you need to move

    git fetch && git checkout branch2
    git cherry-pick commit_id_first..commit_id_last
    git push
    

    Now revert unpushed commits from initial branch

    git fetch && git checkout branch1
    git reset --soft HEAD~1
    
    0 讨论(0)
  • 2020-12-22 16:22

    If you have a low # of commits and you don't care if these are combined into one mega-commit, this works well and isn't as scary as doing git rebase:

    unstage the files (replace 1 with # of commits)

    git reset --soft HEAD~1
    

    create a new branch

    git checkout -b NewBranchName
    

    add the changes

    git add -A
    

    make a commit

    git commit -m "Whatever"
    
    0 讨论(0)
  • 2020-12-22 16:24
    1. Checkout fresh copy of you sources

      git clone ........

    2. Make branch from desired position

      git checkout {position} git checkout -b {branch-name}

    3. Add remote repository

      git remote add shared ../{original sources location}.git

    4. Get remote sources

      git fetch shared

    5. Checkout desired branch

      git checkout {branch-name}

    6. Merge sources

      git merge shared/{original branch from shared repository}

    0 讨论(0)
  • 2020-12-22 16:28

    Here is a much simpler way:

    1. Create a new branch

    2. On your new branch do a git merge master- this will merge your committed (not pushed) changes to your new branch

    3. Delete you local master branch git branch -D master Use -D instead of -d because you want to force delete the branch.

    4. Just do a git fetch on your master branch and do a git pull on your master branch to ensure you have your teams latest code.

    0 讨论(0)
提交回复
热议问题