Reputation: 187
I'm working in branch from develop. My work took long time and develop branch make new commits, so I did rebase.
Now my commit is on top, rest commits are combined and conflicts are solved. There is no problem. But I want to work on one commit. I want to amend my commit.
Can I amend my commit after rebase? Will there be any other problems in the future?
Upvotes: 2
Views: 2652
Reputation: 35655
A picture is worth a thousand words. This is how it will look before you amend:
If you haven't already pushed your repository to the public branch, there is no problem with amending your commit. But if you have already pushed your changes, and they are accepted and other developers are already working on it, then you shouldn't amend that commit.You can still make the change, but do it as an entirely new commit - not an amendment.
This is how it will look after you amend:
If you want to be absolutely safe, create an entirely new commit - don't use the amend flag.
Upvotes: 0
Reputation: 91
You can easily amend the commit in the usual way with git commit --amend
as already mentioned.
However you can reset your last commit continue working directly with the changes of your last commit. This makes it easy to see what changes you have done as you work, rather than continuously amending as you progress.
To do this use the command git reset HEAD~1
. Make sure you have pushed your latest state however just to be safe.
Once you are done you just make a completely new commit.
Upvotes: 1
Reputation: 522171
If you want to amend the top commit on your recently rebased branch, there should be no reason why you cannot do this. Your branch after rebasing is still just a branch, albeit it now has a new base with some fresh commits from the develop
branch. The reason this should not be a problem is that amending would only affect your most recent commit anyway. On top of this, presumably you have not shared this top commit with the public repo yet, so there should be no side effects from an amend.
Upvotes: 4