- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 56 Articles for Git
296 Views
Cherry picking is a way to choose specific commits from one branch and apply them to another branch. This is useful when you want to select specific changes from a pull request.git cherry-pick {commit_hash}The above command will cherry pick the commit associated with the specified commit hash to the current branch.From the above commits shown in the diagram, we need to apply only commit F1 from the feature branch to the master branch.In this case, the master branch after cherry picking will look as below.Example$ dell@DESKTOP-N961NR5 MINGW64 /e/tut_repo $ git init Initialized empty Git repository in E:/tut_repo/.git/ $ dell@DESKTOP-N961NR5 ... Read More
789 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
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
8K+ 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
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
660 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
179 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
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
787 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
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