Git / BitBucket / SourceTree

 Reverting Commits
---------------------

I am new to git but had to do some branching and merging etc. recently.   SourceTree as a git client works quite well. A few things though, at times the changes in repository don't reflect immediately in the SourceTree UI.  Let us say there is a commit from other team member, you may not see it in UI right away but when you do pull from UI, the window which pops up, does show all the changes in remote branches.

There is a very good article for git starters.

http://git-scm.com/book/en/v2/Git-Branching-Basc-Branching-and-Merging

In source tree, you can open the command window by Actions->Open In Terminal.  It will open the Git shell for the selected project. There you can directly execute any command.

I had a situation where I had to revert few commits into one branch. One of the commit was a merge from another branch also.

A----AC1---C2(Merge from A)-----------AC3
B----BC1----(Merge into A)---------------BC2

Let us say I had to revert  the commits AC3 and AC2  on branch A. ( keep in mind here these are published changes..not just in local branch )

1. First I switched to branch A.
 git checkout A

2. I ran following command.

git revert -n AC3 AC2

It failed complaining that there is merge commit  and parent number ( -m ) is not specified.

3. So I thought of reverting one by one , so I executed following command

git revert -n AC3

It complained the revert is already in progress.

4. At this point I had to abort the earlier revert as following.

git revert --abort

5. Now I did the following

git revert -n Ac3
git revert -n Ac2 -m 1 ( 1 indicates  A branch is the parent or main branch , otherwise specify 2) 

7. Finally did a commit for changes reverted.

git commit A

8. Now I wanted to compare the changes between branch A ad B

git diff A B


Aborting a merge
----------------------
Let us say you started a merge by mistake , you want to abort it, use:

git merge --abort
 
 
How to add new folders and files
-----------------------------------------
If you just add empty folder, SourceTree won't display those in the Unstaged files section. But as soon as you add files to the folder, you will see those there.

By the way , you still have to create files and folder using regular OS commands before you could use git commands to add those to local and remote repos.


Renaming a branch
----------------------

http://www.benjaminlhaas.com/blog/locally-and-remotely-renaming-branch-git

Below are the commands in case you don't want to read the whole article above.

git  branch -m  oldBranchName newBranchName
git remote -v
git push  origin :oldBranchName
git push origin newBranchName

9. How to undo local changes in tracked files, which are not staged

git chekcout .






Comments

Popular posts from this blog

SQL

Analytics

DBeaver