Home > OS >  How to commit and push changes of tracking and un tracking files to correct branch in gitlab
How to commit and push changes of tracking and un tracking files to correct branch in gitlab

Time:06-15

We have a master branch in gitlab. And we have release v1 branch under that master branch. Under releasev1 branch I have created my Register branch. I have did checkout through source tree too. But, Some how I switched to master branch unknowingly and my changes are in master branch locally.

While push/commit the code I realise this, My current branch is master. So, I stop the commit/push changes to master.

There are lot of files newly add and also existing file changes too happen.

Is there any possible without discard these changes, push to my Register branch?

I don't want to push these changes to master which is a big problem for us. I just want to push my changes to my Register branch.

Any suggestions?

CodePudding user response:

git stash is an ideal option for you.

Just run git stash in your local repo, it will save your changes in a detached storage and discard them. Then switch to the appropriate Register branch and run git stash pop. If there are any conflicts, it will not remove the stash from the detached storage.

If you are using Sourcetree then use this tutorial: https://confluence.atlassian.com/sourcetreekb/stash-a-file-with-sourcetree-785332122.html

CodePudding user response:

I presume you are saying you have committed to master but you intended to commit to register. No problem. You can easily move the commits (in effect).

Let's say you have this:

A -- B -- C -- Oops1 -- Oops2 -- Oops3 (master)
X -- Y -- Z (register)

Switch to register, then cherry-pick the Oops commits, which copies them onto register. Finally, to erase the original Oops commits, switch to master and reset --hard back to C.

There is a cleverer way using rebase but what I've described is easy.

  • Related