git checkout master # first get back to master
git checkout experiment doc/* app.js package.json # then copy the version of files from branch "experiment"
git add .
git commit -m "added something"
git checkout seotweaks
git merge -s ours master
git checkout master
git merge seotweaks
I generally like to merge master into the development first so that if there are any conflicts, I can resolve in the development branch itself and my master remains clean.
(on branch development)$ git merge master
(resolve any merge conflicts if there are any)
git checkout master
git merge development (there won't be any conflicts now)
git log --pretty=oneline --abbrev-commit
46cd867 Changed with mistake
d9f1cf5 Changed again
105fd3d Changed content
df33c8a First commit
git rebase -i HEAD~2
Editor is shown as below:
pick d9f1cf5 Changed again
pick 46cd867 Changed with mistake
# Rebase 105fd3d..46cd867 onto 105fd3d
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#
One thing to notice here is that the most recent commit is the one at the bottom. We just need to delete the line that corresponds to the commit we want to delete and save the file.
We can see that the change was applied correctly:
git log --pretty=oneline --abbrev-commit
d9f1cf5 Changed again
105fd3d Changed content
df33c8a First commit
To remove a commit you already pushed to your origin or to another remote repository you have to first delete it locally like in the previous step and then push your changes to the remote.
git push origin +master
Notice the + sign before the name of the branch you are pushing, this tells git to force the push.