https://help.github.com/articles/changing-a-commit-message/
* git checkout your-branch
* git rebase -i HEAD~N (N is the number of commits)
* use **reword**
* Follow the steps
* git push --force
git checkout master
git fetch upstream
git rebase upstream master
git checkout <your-branch>
git rebase -i master
git checkout your-branch
git rebase -i HEAD~N
git fetch upstream
git rebase upstream/master
git push --force
Git cherry-pick allows you to merge a single commit from one branch into another. To use the cherry-pick command follow these steps:
- Check out the branch into which you want to merge the commit. (E.g.:
git checkout master
) - Identify the commit hash through your favorite method. You can use git log, a GUI tool such as sourcetree or tower, or if you use GitHub or BitBucket you can use their interface. In SWS we use GitHub, so I tend to use that method often. With GitHub you can find the commit hash on the commit list page or on the individual commit page itself. See the screenshots below.
Pick'em! -
git cherry-pick 9638d99c89a92350ad2f205f47af24b81ac39a64
- If there is a merge conflict you will have to resolve that with your favorite merge tool, but otherwise you have now successfully pulled in the work from the other branch.
If there are 5 commits in a PR and you want to squash them into one, follow this steps -
git rebase -i HEAD~5
- In the text editor that comes up, replace the words "pick" with "squash" next to the commits you want to squash into the commit before it.
- Save and close the editor
- git will combine the "squash"'ed commits with the one before it. Git will then give you the opportunity to change your commit message.
- Use
git show
to check if everything is fine - If you've already pushed commits to GitHub, and then squash them locally, you will have to force the push to your branch.
git push -f or git push origin branch-name --force
* git commit --amend
* Change the commit message
* git push -f
There are couple of options to achieve this -
- Save following function in your bashrc/zshrc and run
pullpr 123
function pullpr() {
git fetch origin pull/$1/head:$1;
git checkout $1;
}
- Run following bash script -
#!/bin/bash
set -e
set -x
if ! git diff-index --quiet HEAD; then
set +x
echo "There are uncommitted changes:"
git status --short
echo "Doing nothing to avoid losing your work."
exit 1
fi
request_id="$1"
remote=${2:-"origin"}
git fetch "$remote" "pull/$request_id/head"
git checkout -B "review-original-${request_id}"
git reset --hard FETCH_HEAD
- Easiest way is to use hub -
hub checkout https://github.com/zulip/zulip-electron/pull/353
- remove a local branch from your machine:
git branch -d {the_local_branch} (use -D instead to force deleting the branch without checking merged status)
- To remove a remote branch from the server:
git push origin --delete {the_remote_branch}
- You can also make a function in your bashrc/zshrc:
function rmbranch() {
git push origin --delete $1;
git branch -D $1;
}
then use it like rmbranch dev
.
- So for an example if you want to push branch1 to branch2 then
From branch1
git push origin branch1:branch2 -f
or
git push origin push_from_branch:push_to_this_branch -f
git reset --hard HEAD~1 (changes to last commit will be removed )
or
git reset --soft HEAD~1 (changes to last commit will be available as uncommited local modifications)
git stash clear
git remote add username https://github.com/username/repo.git
git fetch username branch
git checkout username/branch
This is pretty useful if you just want to exclude some files from git diff.
git diff -- . ':(exclude)*-lock.json'
git log -S "no-select" --stat -p -- path-of-the-file