Showing posts with label git. Show all posts
Showing posts with label git. Show all posts

how to merge a specific commit in Git

In this article am going to explain how to merge(cherry pick) specific commit in Git

When you are working on two different branches you often merge code from one branch to another. But if you want to merge specific changes to another branch you can do it by cherry picking specific commit.

Using Git Extensions you can easily merge a specific commit. (Download Git Extensions from link1 or from here link2)

In Git Extensions open your repository. It will show you all the commits. Select any specific commit and right click on it. Then select cherry pick commit. Check the below screenshot for reference


Once you select Cherry pick commit it opens another small popup as shown below


Check "Automatically create a commit" if you want to automatically commit this changes into current branch or if you want to manually commit, keep the box unchecked and click on "Cherry pick".

In this way you can merge a specific commit in Git
Read more...

How to undo or revert last commit(s) in Git

When you are working on git, it is possible that sometimes you may commit the wrong files or the code you committed some times needs to be reverted back.

There are many ways to revert the last commit or any specific commit in git. This SO post has many answers which explains how to revert a commit. But those are to be done in a command prompt which many are un-familiar with. So here am going to explain a easy way to revert a commit in git.

This can be achieved using Git Extensions. You can download it from here link1 or from here link2

Once you download Git Extensions, open it and select the repository where your source code exists.

Once this is done Git Extensions will show you all the commits. Select any specific commit and right click on it. Then select revert commit. Check the below screenshot for reference


Once you select the Revert Commit option, it opens a pop-up like below


Select "Automatically create a commit" if you want to directly commit the reverted changes or if you want to manually commit the reverted changes keep the box un-selected and click on "Revert this commit" button.

In this way you can easily revert any commit in git using Git Extensions.

For more useful articles on git visit this link: Git

Read more...

GIT Error : Cannot switch to master because there are uncommitted changes. Commit or undo your changes before you switch branches

Today i came across a weird issue when i was trying to switch from my stage branch to main branch. Visual Studio was showing following error:

Cannot switch to master because there are uncommitted changes. Commit or undo your changes before you switch branches. See the Output window for details.


Visual studio states that we cannot switch to other branch when there are uncommitted changes. But in my case i don't have any pending/uncommitted changes. So, as suggested in the error message i had a look at the output window.
Following is the error shown in my output window.

It states that there are some changes in the ResourcesController.cs file. But i din't have any changes in that file.

Fix for the Issue:

So, to fix the issue i just deleted the above file and did undo (From Team Explorer) to add it again. I tried to switch branch now and it WORKED!!
This way i solved the error "cannot switch to master because there are uncommitted changes. Commit or undo your changes before you switch branches. See the Output window for details."
This is the solution which worked for me. But, it may not be the ideal solution and no guarantee that it works for all. But it worked for most of the people.

Update (Fix 2):

If the above solution did not work, try to change the branch directly from Git Extensions. Just open the Git Extensions and select the branch from branch drop down.


If you find any other way to fix this problem please do comment below so that it may help others.
Read more...