Reputation: 19147
I am still learning the features of using TortoiseGit and the concept of version control.
I have read the this article and it is not clear to me if I need to follow that procedure. It describes patching.
So, I have this feature branch that has now been merged into the master as indicated. I want to have a go at making a revision to the application with respects to one of the commits (highlighted). So I would like to try out an idea to do things differently and implement it if I am happy.
What is the correct way to do this? I am a sole developer and am not in collaboration with others for my project.
Thank you for your advice.
Upvotes: 2
Views: 568
Reputation: 34002
There will always be times when you realize that a commit is not perfect or introduced an error.
You have several options:
1) Fix the issue and commit the fix on master
(or in a bugfix/feature branch). You should do this, especially, if the "faulty" commit is some longer time ago.
2) Option 1 might have the disadvantage that you don't know that this fix belogs to a recent feature branch. Here, you could switch to the feature branch again (if you already deleted the branch, re-create it on the latest commit before the merge), commit the fix there and merge the feature branch again to master
. This way you can see in the log that this fix also belongs to the feature branch.
3) The third option would be to rewrite your history - the is especially discouraged if you develop with other users and the "faulty" commit is already pushed or older. For rewriting history, go to the log dialog and open the context menu on the commit just before the faulty commit and select "Rebase ... onto this". Then the rebase dialog opens, check "Preserve merges" and "Force" there - then all commits starting with the "faulty" one should be displayed. Now, click on the "faulty" commit and mark it as "Edit" and then start the rebase. - Now your working tree is put back into that old state. Do your changes on the working tree, check "Edit/Split commit" and click on "Amend" on the rebase dialog. - After that all other remaining commits are re-applied and the fix is included in your history.
PS: The article about patches and pull requests is about sharing changes with other developers.
Upvotes: 3
Reputation: 9481
If you don't want to preserve your history tree as is just do the following steps:
Start interactive rebase git rebase -i 'xxxxxxx'
where xxxxxx
is commit id of the commit with the comment 'Removed MWB files....'
In your rebase sheet edit the line of the commit that you want to change by replacing 'pick' with 'edit'
When rebase stops. Do 'git reset HEAD~' this will put your working directory into the state that was right before you committed these changes.
Make changes to your files, commit them.
Do git rebase --continue
Push your master branch with --force
option
PROFIT
BEFORE YOU DO THIS. MAKE SURE TO CREATE A BACKUP COPY OF YOUR MASTER BRANCH
If something goes wrong you can restore master branch from the backup by doing
git checkout master
git reset --hard backup-master
git push --force
Upvotes: 2
Reputation: 9481
If you are sole developer and you are absolutely sure that no external party has checked out your master you can do the following:
Create backup of your master branch by branching off from the top of current master.
Looks like you also have changes committed to your master branch. Create a feature branch on from the master as well. At this point master-backup branch and your new-branch should be identical
Reset your master to the state before your merged in your feature branch. In this case this is 'Removed MWB files....'
Checkout your feature branch you want to change
Do git rebase -i master
Edit the line that has your commit that you want to change. Change 'pick' to 'e' and save the file to kick off interactive rebase
When rebase stops at the commit you want to change do git reset HEAD~
this will put your working directory into the state before you did your commit. With all changes being on the index.
Make necessary changes to your source and commit
Do git rebase continue
Once interactive rebase finishes. Checkout master and merge your new feature branch into int.
Checkout your next branch 'lingala' translation.
Rebase it on top of new master, and then merge
Checkout your feature/new-branch, and rebase on top of new master then merge
You done. Push everything to your remote. Note that you have to use 'git push --force'
If you have code checkout on other machines, make sure to do the following
git fetch ; git checkout master ; git reset --hard origin/master
Note the last step will destroy any local changes you have on your master branch and any uncommitted files. If you want to preserve them either stash them or create a temp local branch that you can later rebase on top of new master
Upvotes: 2