FAQ's
How to extract commit message from the given commit ID?
$ git show -s --format=%B <COMMIT-ID>
or
git log --format=%B -n1 <COMMIT-ID>
How to list commits submitted only on the specified branch?
$ git log <branch-name>
How to get the commit-ID, a remote tracking branch is pointing to?
After fetch, if you want to know which commit-ID the remote tracking branch is pointing to, you can simply use the log command on remote tracking branch.
Ex: $ git log origin/rel-sa81-8.1-r.3 -2
If you run the same command on local branch, you will see the difference
Ex: $ git l1 rel-sa81-8.1-r.3 -2
How to fetch and rebase commits from remote branches?
I need to fetch changes only from a remote branch origin/rel-sa81-8.1-r.3.
$ git fetch origin rel-sa81-8.1-r.3
Now rebase the local branch with fetched commits
$ git rebase origin/rel-sa81-8.1-r.3
How to update a Personal repo "master" branch with remote reference repo "master" branch?
I have a personal repo by name "siddesh-myProduct" and it is a fork of "myProduct" repo.
Now "myProduct/master" branch got many commits after I forked "siddesh-myProduct/master".
Too synchronize "siddesh-myProduct/master" with it's reference, I use rebase.
#First create a remote pointer to "myProduct" repo.
$ git remote add myProduct https://siddesh@my.company.git/stash/scm/myProject/myProduct.git
# Fetch changes
$ git fetch myProduct
#rebase
$ git rebase myProduct/master
#Push changes to my personal repo "siddesh-myProduct"
$ git push origin master
How to squash 2 commits into one?
git rebase -i origin/bugfix/PRS-326493~2 bugfix/PRS-326493
git push origin +bugfix/PRS-326493
git reset --hard <the sha1 hash>
git push origin +bugfix/PRS-326493
How to discard last commit?
git reset --hard HEAD~1git reset --hard <the sha1 hash>
No comments:
Post a Comment