Back to home


How to Tag commits in the repository (Git)
Oct 06, 2020 9.9k 65 minutes ago

Before we start, you must go to the jgit directory, where we made the original clone for this post. We should start by tagging the commit that is ten commits behind origin/stable-2.3 and is not a merge. In order to find that commit, we will use the git log command. Step 1 : Find the commit as follows: git checkout stable-2.3 git log -11 --no-merges --oneline Step 2 : Now that we have found the 60d538f commit, we should make it a lightweight tag. Use the git tag command to give a meaningful rel

How to Push Git notes to a remote repository (Git)
Oct 06, 2020 11.2k 65 minutes ago

Before we can push the notes from the shareNotes repository, we have to create a note to be pushed, as the notes we have now are all available on the remote repository. The remote repository in this case is the jgit directory: Step 1 : You have found a commit you would like to add a note to, and you want to add the note to the verified reference: git notes --ref verified add -m "Verified by admin@devtutorial.io" 871ee53b52a Step 2 : Now that we have added the note, we can list it with the git l

How to Retrieve notes from the remote repository (Git)
Oct 06, 2020 7.3k 65 minutes ago

we need another clone from the local clone we already have. This is to show the push and fetch mechanism of Git with git notes. Step 1 : Start by checking out the master branch: git checkout master Step 2 : Now, create a local branch of all the stable-3.1 branches: git branch stable-3.1 origin/stable-3.1 Step 3 : We are checking out all these branches because we want to clone this repository and, by default, all the refs/heads/* branches will be cloned. So, when we clone the jgit directory,

How to Separate notes by category (Git)
Oct 06, 2020 6.8k 65 minutes ago

As we saw in the previous example, we can add notes to the commits; however, in some cases, it makes sense to store the information sorted by categories. Notes are stored in refs/notes/commits, but we can add multiple references so that we can easily sort and list the various scopes of the notes. Step 1 : we need a new branch that tracks the origin/stable-3.1 branch; we name the branch notesReferences, and create and checkout the branch with the following command: git checkout -b notesReferences

How to Add a Git note (Git)
Oct 06, 2020 12.3k 65 minutes ago

We will add some extra information to the already released code. If we were doing it in the actual commits, we would see the commit hashes change. Step 1 : Before we start, we need a repository to work in; you can use the previous clone of jgit, you can clone the jgit repository as follows: git clone https://git.eclipse.org/r/jgit/jgit cd jgit Step 2 : Checkout the branch notesMessage tracking origin/stable-3.2 git checkout -b notesMessage --track origin/stable-3.2 Step 3 : List the commit h

How to Add rebase with autosquash (Git)
Oct 04, 2020 7.4k 65 minutes ago

We will create a branch from origin/master so we are ready to add commits to our fix. Let's start with something like this: git checkout -b readme_update_developer --track origin/master Step 1 : Start by echoing some text into README.md: echo "More information for developers" >> README.md Step 2 : This will append more information to README.md for developers; verify that the file has changed using the Git status as follows: git status Step 3 : Now, we want to add and commit this. We can

How to Change the author of commits using a rebase (Git)
Oct 04, 2020 14.4k 65 minutes ago

When starting to work on a new project, it is common to forget to set the author name and author email address for the specified project. Therefore, you will often have commits in your local branch that have been committed with the wrong username and/or email ID. Step 1 : We need a branch, as always with Git. Name the branch resetAuthorRebase and make it track origin/master. Use the following command to achieve this: git checkout -b resetAuthorRebase -t origin/master Step 2 : Change the author

How to squash commits using an interactive rebase
Oct 04, 2020 18.5k 65 minutes ago

To get started with this example, we need a new branch, namely rebaseExample3, which tracks origin/stable-3.1. Step 1 : Create the branch with the following command: git checkout -b rebaseExample3 --track origin/stable-3.1 Step 2 : Find a commit that is between origin/stable-3.1 and origin/stable-3.2, and list the commits in reverse order. Alternatively, you can scroll down to the bottom of the output and find the commit we will use, as shown in the following snippet: git log origin/stable-3.1.

How to rebase selected commits interactively (Git)
Oct 03, 2020 11.2k 65 minutes ago

When you are working on a new feature and have branched from an old release into a feature branch, you might want to rebase this branch onto the latest release. When looking into the list of commits on the feature branch, you may realize that some of the commits are not suitable for the new release. In that case, when you want to rebase the branch onto a new release, you will need to remove some commits. This can be achieved with interactive rebasing, where Git gives you the option to pick the c

How to resolve conflicts during a Git rebase (Git)
Oct 03, 2020 11.0k 65 minutes ago

When you rebase a commit or a branch on top of a different HEAD, you may eventually see a conflict. If there is a conflict, you will be asked to solve the merge conflict and continue with the rebase using git rebase --continue. Step 1 : Check out the branch named rebaseExample2, which tracks origin/stable-3.1: git checkout -b rebaseExample2 --track origin/stable-3.1 Step 2 : Make a commit on the branch: echo "rebaseExample2">rebaseExample.txt git add rebaseExample.txt git commit -m "rebaseEx

How to rebase commits to another branch (Git)
Oct 03, 2020 11.4k 65 minutes ago

we are going to perform a very simple rebase, where we will introduce a new file, commit that file, make a change to it, and then commit it again so that we end up with two new commits. Step 1 : The jgit repository can be cloned as follows git clone https://git.eclipse.org/r/jgit/jgit cd jgit Step 2 : Check out a new branch, rebaseExample, which tracks origin/stable-3.1: git checkout -b rebaseExample --track origin/stable-3.1 Step 3 : Make two commits on the rebaseExample branch, as follows: e

How to Create an orphan branch (Git)
Oct 02, 2020 21.5k 65 minutes ago

You are now familiar with Git's data model, the DAG. You have seen that objects have a parent. When you create a new branch, the commit is its parent. However, in some situations, it is useful to have a branch with no parent. Step 1 : It is actually easy to create an orphan branch. The flag --orphan to checkout will do it. It can be executed as follows: git clone https://github.com/devtutorialio/Git-s-objects.git cd Git-s-objects git checkout --orphan fresh-start Step 2 : We now have a branch

How to check the difference between branches (Git)
Oct 02, 2020 7.9k 65 minutes ago

A regular git diff between two branches will show you all the information, but it can be rather exhausting to sit and look at; maybe you are only interested in one file. Thus, you don't need the long unified diff. Perform the following steps to see the difference between the branches: Step 1 : Diff origin/stable-3.1 with the origin/stable-3.2 branch: #git diff [options] <commit> <commit> <path></path> git diff --name-only origin/stable-3.1 origin/stable-3.2 org.eclipse.jg

How to use git reuse recorded resolution (rerere) to merge Git conflicts
Oct 02, 2020 7.5k 65 minutes ago

When you work on long-living feature branches, you end up in a situation where you have the same conflicts occurring repeatedly. Here, you can use git rerere, which stands for reuse recorded resolution. Git rerere is not enabled by default, but can be enabled with the following command: git config rerere.enabled true Step 1 : In the jgit repository folder, start by checking out a branch that tracks origin/stable-2.2: git checkout -b rerereExample --track origin/stable-2.2 Step 2 : Now, change

How to force a merge commit (Git)
Oct 02, 2020 19.8k 65 minutes ago

Git supports almost any workflow. We have often encountered a situation that requires a merge commit while merging a feature, even though it can be done with a fast-forward merge. Those who requested it often use it to indicate that you have actually merged in a feature and want to store the information in the repository. Step 1 : Start by checking out a local branch remoteOldbugFix that tracks origin/stable-3.1: git clone https://git.eclipse.org/r/jgit/jgit cd jgit git checkout -b remoteOldBu