I currently use git the following way:
- clone, fetch repo
- create topic branch for specific issue
- do some commits on it
- checkout master branch
- merge topic branch to master
- push new master branch
Unfortunately this is getting messy from time to time. What I would like to do is to merge some smaller commits to a bigger one.
Also it would be sometimes a good idea to merge all commits in a new branch to one commit and merge this to master.
example:
git branch update-docs
git checkout update-docs
git add -A .
git commit -m 'updated networking doc'
git add -A .
git commit -m 'updated manager doc'
git checkout master
git merge update-docs
As you know now I would have two commits in master branch “updated networking doc” and “updated manager doc”.
If I would now want only have one commit in master branch called “updated docs” for example which contains the changes of these two commits what do I have to do?
I think you have to use git rebase for this sort of task. I just do not know how to use it.
I already tried:
git checkout master
git rebase update-docs
but that merged the changes to master without leaving any commits and now the repo is messed up.
So would somebody share the commands you have to use?
Solution:
git checkout -b update-readme
git commit -am 'rewritten readme'
git commit -am 'added author name'
git rebase -i master
opens text editor:
pick 6dbcbf1 rewritten readme
pick b815bbf added author name
now you change this to:
pick 6dbcbf1 rewritten readme
squash b815bbf added author name
then you save with “:w” and “:q” if using vim and it will open another editor where you can define the new commit name
rewritten readme
then you merge the repo:
git checkout master
git merge update-readme
After
git merge update-docs, executegit rebase -i origin/master. This will pop up an interactive rebase editor, which allows you to squash commits and otherwise rearrange them.