Use of Branches:
You can create different branches of your working tree with different names. For example if you don’t want to make changes on your working tree (clone repository on your system) you can create a new branch and make changes in it, add new files and when the work in the branch is complete then you can merge those changes with your working tree and commit to the remote repository. You can do this in Eclipse or also by using the command line:
Using Command line
To create a new branch using command line using the following command:
git checkout -b new_branch
You can add new files to this branch independent of the master branch by typing this:
git add new_file
And then commit it using the following command:
git commit -m “new_file file” new_branch
After changes in new file you can merge these changes with your master branch using following commands:
git checkout master
git merge new_branch –no-ff
By using Eclipse it is very simple to create a new branch by using this:
Team > Switch To > New Branch
Branche makes it easy for the user to work in the same repository without affecting the master branch. User can work on the same file with different code in different branches.
Resetting your current HEAD
Sometimes due to a conflict, we are not able to pull or push changes. Then you need to revert changes to a particular commit. In that case, Git offers you the possibility to reset the Head of the current branch to any other commit. It optionally resets the index and the working tree to match that commit. Note that this action affects all files and folders in the entire repository.
You have the option to do a hard reset, a mixed reset, and a soft reset:
- soft – the HEAD points now to the new commit, the index and the working tree are unchanged.
- mixed – the HEAD points now to the new commit, the index is updated, the working tree is unchanged.
- hard – the HEAD points now to the new commit, the index and the working tree are updated.
Reset to specific branch or tag:
Select Team -> Reset… on a project. This opens a dialog (as you can see in the screenshot below) where you can select a branch or a tag:
Reset to a specific commit:
Select a commit in the History view and open the context menu. Here you find the entries Hard reset, Mixed reset and Soft reset.
Revert all local and staged changes
This can be done using a hard reset. If you reset to the current HEAD (normally the last commit on your branch) with the option hard you reset the currently checked out branch to this commit and overwrite the working tree and the index with the content of HEAD. You can do this in 3 ways:
- Select Team > Reset… on a project. In the dialog select HEAD or your current branch and switch the radio button to hard.
- Right-click and select Reset… on any branch or tag in the Repositories view. This opens a dialog which lets you decide on the reset type. Choose hard here.
- Open the context menu on the HEAD commit in the history view and select Hard Reset.
Use of Tags:
In git, you can create a tag of a previous commit. It will make it easier to find that particular commit and push those changes again if you want to use those changes.
Go to Team > Show in history
And select the particular commit for a tag and after right click selects the option Create Tag.
Then fill the tag name and message as you can see in below screenshot:
As you can see in below screenshot tag is created successfully so now you have that particular commit attached to the tag. You don’t need to find it from history view. You just have to select and push if you want: