Git tips and tricks

git rebase --interactive 8bf4b651207c8e60abf3822a276868942f1efe7a

git commit --amend --author="Suchi Garg <suchi@example.com>"

git rebase --continue

Problem - squash commits

Suppose a branch has 3 commits and you want to squash all of them in one.

git rebase -i master

Your editor will open with a file like

pick fda59df commit 1
pick x536897 commit 2
pick c01a668 commit 3

 

Each line represents a commit (in chronological order, the latest commit will be at the bottom).

To transform all these commits into a single one, change the file to this:

pick fda59df commit 1
squash x536897 commit 2
squash c01a668 commit 3


This means, you take the first commit, and squash the following onto it. If you remove a line, the corresponding commit is actually really lost. Don't bother changing the commit messages because they are ignored. After saving the squash settings, your editor will open once more to ask for a commit message for the squashed commit.

---------------------

With the remote branches in hand, you now need to check out the branch you are interested in, giving you a local working copy:

git checkout -b test origin/test

 

delete a remote branch

git push origin --delete WIZ-7488-Article-Theming

 

Create a patch file using git diff:

git diff --no-prefix --color=never > patchfile

------------------------

Problem - two repositories need to be merged. A  and B are 2 repos, B has latest code -> all code in B master need to be merged in A master

 

 

  1.     
  2. git clone A.git
  3.     
  4. git remote add B B.git
  5.     
  6. git fetch B
  7.     
  8. git checkout -b masterB b/master
  9.     
  10. git checkout masterB
  11.     
  12. git merge -s ours master
  13.     
  14. git checkout master
  15.     
  16. git merge masterB
  17.     
  18. git push origin master

And you are done.

 

Tags