0

I am not too familiar with git. I have one situation.

Flow is like that =>

  • I create new branch from develop
  • Updated code 1

====>Forget to commit and push

====>Forget to create new branch and pull

  • Update code 2 again for the new branch (But its still at old branch)

Now I am here.

How can I do

  • Commit and push updated code 1 to old branch
  • Create a new branch for updated code 2 and commit and push updated code 2 ??
mike
  • 1,233
  • 1
  • 15
  • 36
Loran
  • 772
  • 4
  • 16
  • 38
  • Does this answer your question? [How do I move a commit between branches in Git?](https://stackoverflow.com/questions/3710192/how-do-i-move-a-commit-between-branches-in-git) – Liam Oct 02 '20 at 07:26
  • [Create a new branch](https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging) and [cherry pick](https://git-scm.com/docs/git-cherry-pick) the commits from old to new. Then [reset](https://git-scm.com/docs/git-reset) old to remove the commits you don't want – Liam Oct 02 '20 at 07:27

1 Answers1

1

Assuming Code 1 and Code 2 are two different files, you can do the following:

git add code1 // add code1 to current branch, but not code2

git commit -m "adding code1"

git push origin current-branch

git checkout -b new-branch // create new branch, you may want to move back to dev before doing that

git add code2 // add code2 to the new branch you created

git commit -m "adding code2"

git push origin new-branch

Finally, you will have current-branch with only code1 and new-branch containing both code1 and code2. If you move back to dev before creating new-branch, it will only contain code2, but not code1.

SwissCodeMen
  • 4,222
  • 8
  • 24
  • 34
Leafar
  • 364
  • 2
  • 10