Found 56 Articles for GitHub

Explain rebasing in Git

Kannan Sudhakaran
Updated on 30-Apr-2021 08:34:57

798 Views

Rebasing alters a sequence of commits. It moves or relocates a sequence of commits from current branch to the target branch. By default, the commits from the current branch that are not already on the other branch are rebased. Rebasing technique allows us to keep a linear history.Let us understand from this from the diagram below.To rebase we need to be in the branch which needs to be rebased into the target. In our scenario, we need to execute the rebase command on the feature branch. After executing the rebase command we will get a linear history.After executing the rebase ... Read More

Explain squash merging in Git

Kannan Sudhakaran
Updated on 30-Apr-2021 08:29:06

1K+ Views

Imagine if your feature branch has large number of commits- E.g. 100s commits. Rather than merging all commits individually from feature to master, there is an option to add up all commits into a single commit. This is called a squash commit because it "squashes" all the individual commits into one big change. As far as the history of the master branch is concerned, the history of the feature branch would be lost.We can use the following command to squash-merge the commits of a branch to the master branch.$ git merge --squash feature_branchThe diagram shows that we have 3 commits ... Read More

How to undo a faulty merge with revert command in Git?

Kannan Sudhakaran
Updated on 30-Apr-2021 08:25:22

9K+ Views

Let us say we performed a merge commit, shared this commit and later found out that the code is not compiling or our application is not working. This happens if we make mistakes while merging. In situations like these we need to undo the merge using the git revert command.Consider the following diagram, where the repository has two branches – master and a feature branch. Both the branches are diverged and have two commits each. The commits in the feature branch the (C3 and C4) are merged into the master branch and the resulting commit is shared. Let us assume ... Read More

How to undo a faulty merge with reset command in Git?

Kannan Sudhakaran
Updated on 30-Apr-2021 08:22:06

2K+ Views

Let us say we performed a merge commit and later found out that the code is not compiling or our application is not working. This happens if we make mistakes while merging. In situations like these we need to undo the merge using either −reset command; ORrevert commandThe git reset command can be used to undo local changes to the state of a Git repository. A git reset moves the HEAD pointer to a given commit and updates the index to match that commit. This command rewrites the commit history. However, if we have shared our commits with other team ... Read More

Explain soft reset with an example in Git

Kannan Sudhakaran
Updated on 30-Apr-2021 08:18:54

671 Views

Soft reset will move the HEAD pointer to the commit specified. This will not reset the staging area or the working directory.ExampleThe diagram shows a file named File1.txt within the git repository. A, B, C and D represent lines that are added to the file. The diagram indicates that a commit is performed after adding each line A, B and C. c1 is the commit performed after adding line A, c2 is the commit after adding line B and C3 represents the commit after adding line C.Now add line D. This change is available in the working directory and this ... Read More

Explain mixed reset with an example in Git

Kannan Sudhakaran
Updated on 30-Apr-2021 08:15:25

181 Views

Mixed reset will move the HEAD pointer to the commit specified. This is the default reset option in git. It also copies content of the commit snapshot to the staging area and not to the working directory. This will lead to overwriting the staging area. The working directory contents will be safe in this case. Let us understand this through an example.ExampleThe diagram shows a file named File1.txt within the git repository. A, B, C and D represent lines that are added to the file. The diagram indicates that a commit is performed after adding each line A, B and ... Read More

Explain hard reset with an example in Git

Kannan Sudhakaran
Updated on 29-Apr-2021 11:19:45

121 Views

The diagram shows a file named File1.txt within the git repository. A, B, C and D represent lines that are added to the file. The diagram indicates that a commit is performed after adding each line A, B and C. c1 is the commit performed after adding line A, c2 is the commit after adding line B and C3 represents the commit after adding line C. Now add line D. This change is available in the working directory and this change is staged but yet to be committed.Now if we perform a hard reset to move the HEAD pointer of ... Read More

Explain how reset command works in Git

Kannan Sudhakaran
Updated on 30-Apr-2021 08:11:58

790 Views

The commit command moves the HEAD of a branch implicitly. The below diagram shows that initially HEAD was pointing to commit c1. After each commit operation the HEAD pointer moves ahead to the new commit. We can perform a reset using the HEAD pointer or commit hash.The git reset command will explicitly or forcibly move the HEAD of the branch to a specific commit.When resetting the HEAD pointer, we have 3 options −SoftMixedHardHard ResetWhen performing a hard reset, git will copy the commit snapshot into the working area as well as the staging area. Due to this any changes done ... Read More

How to abort a merge conflict in Git?

Kannan Sudhakaran
Updated on 30-Apr-2021 08:03:28

2K+ Views

When doing a merge, you may run into one or more conflicts. Now what if we are not quite ready to handle this conflict yet. Perhaps you have several conflicts and you don't have enough time to spend on resolving these conflicts. In situations like this we can easily go back to the state before we started the merge.To abort the merge, we can use the following command$ git merge --abortNote that if we execute this command after resolving some conflicts and staging the changes, then these changes would not be saved. Once the command is fired, we are back ... Read More

What is merge conflict in Git? How to handle merge conflicts?

Kannan Sudhakaran
Updated on 30-Apr-2021 08:01:14

723 Views

In real world, when we merge branches, we will run into conflicts quite often. Conflict happens because of the following reasons −When the same line of code is changed in different ways in two branches.A given file is changed in one branch but deleted in another branch.Same file is added twice in two different branches but the content of the file is different.In these cases, git will stop the merge process as it cannot figure out how to merge the changes. In such scenarios we need to intervene manually and instruct how to proceed with the merging process.The diagram given ... Read More

Advertisements