Reputation: 1249
Unfortunately I have committed few files in one branch but my intention was to commit those files in other new branch. I have not pushed that file in that branch till now. So please let me know how to move that committed files in my new branch?
Any suggestion will be appreciated.
Upvotes: 6
Views: 909
Reputation: 5074
You could uncommit your files with git reset --soft HEAD^
and then stash your changes with git stash
. Then you can checkout your correct target branch of your changes with git checkout your-target-branch
and at which point you can then do git stash pop
to get your stashed changes and will allow you to add/commit/push in your correct branch.
Upvotes: 2
Reputation: 3386
Suppose the current branch is A. Create a new branch from this branch.
git checkout A
git branch B
Now branch B contains the changes you have committed in branch A. All that is left to do is to remove the changes from branch A. This can be done as follows:
git reflog
This will give you a list of all the changes the repo went through. Pick the HEAD value to which you want the branch A be reverted to.
git reset --hard HEAD<i>
This will do what you intend to do.
Upvotes: 0
Reputation: 1328212
You can create a new branch right where your new commits are:
git checkout -b aNewBranch
x--X--y--y (aBranch, newBranch)
And you can reset the branch you were back to its correct commit (do a git log
to get the right SHA1, it actually could be origin/aBanch
since you didn't push it yet)
git branch -f aBranch <sha1>
x--X (aBranch)
\
--y--y (newBranch)
Upvotes: 0