Trip
Trip

Reputation: 27114

Having already made changes to the git, can I commit these changes to a new branch?

If so, what is the command for that?

Thanks so much SO community!

Upvotes: 1

Views: 105

Answers (3)

ralphtheninja
ralphtheninja

Reputation: 133098

It seems you already have commited changes that you want to commit again, but on another branch. Then you are looking for git cherry-pick

Upvotes: 0

Fredrik Pihl
Fredrik Pihl

Reputation: 45672

SO to the rescue Git for beginners: The definitive practical guide

Upvotes: 0

Seth Robertson
Seth Robertson

Reputation: 31461

If you have not committed:

git checkout -b newbranch; git commit

If you have committed:

git checkout -b newbranch

If you have committed and not pushed and want to remove them from the old branch:

git checkout -b newbranch; git checkout oldbranch; git reset --hard HEAD^

If you have committed and pushed and want to remove them from the old branch:

git checkout -b newbranch; git checkout oldbranch; git revert HEAD

I strongly recommend reading the Pro Git book. http://progit.org

Upvotes: 5

Related Questions