When you send a patch-set to the Linux Kernel’s Upstream, the reviews might include some suggestions that need to be altered in few specific patches. This requires moving your git commit history to a specific patch and correcting it. This, if not done correctly might lead to an increased amount of work. Today, in this blog post, I am going to share some Git tips which I frequently use to tackle the same issue.
The foremost thing is to work in branches. You should always dedicate a branch for a specific type of work. This helps you to reduce the overhead of moving back a lot to fix a particular patch. A new branch can be created using the following command:
git checkout -b <branch-name>
You can list all the branches present in your working directory using:
git branch -a
Once you feel that a branch’s work is done and it is rendered useless, you can easily delete it using:
git branch -d <branch-name>
You can also list the commit log of your current branch with the help of following command
git log --pretty=oneline --abbrev-commit
Now, moving forward to fixing a specific patch which involves re-basing. Git offers an interactive Re-base mechanism to fix specific patches. This can be done using the following commands:
Consider a case, where you want to fix a particular commit (say bbc569ef). You can move back to this particular commit using:
git rebase --interactive bbc569ef^
In the default editor, modify ‘pick’ to ‘edit’ in the line whose commit you want to modify. Make your changes and then stage them with
git add <file-name>
Now you can use
git commit --amend
to modify the commit and
git rebase --continue
to return back to the previous head commit.
These few tips help me a lot while working with the patch traffic. Hope this helps you all as well.