Read last commit of the git and commit number

git show commit changes
git log
git revert last commit
git undo last commit
git show commit files
git commit
git commit number
git show commit details

In maven project with Git source code, Is it possible whenever I am compiling a build with maven, to read the last commit of the git and commit number.

I want to use that commit number to be able to find the last commit.

This is assuming you want to read that information, then store it in a property file. Based on https://github.com/ktoso/maven-git-commit-id-plugin#using-the-plugin:

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <!-- snip other stuff... -->
    <build>
        <!-- GIT COMMIT ID PLUGIN CONFIGURATION -->
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/*.properties</include>
                </includes>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <groupId>pl.project13.maven</groupId>
                <artifactId>git-commit-id-plugin</artifactId>
                <version>2.2.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>revision</goal>
                         </goals>
                    </execution>
                </executions>

                <configuration>
                    <commitIdGenerationMode>flat</commitIdGenerationMode>
                    <gitDescribe>
                        <skip>true</skip>
                    </gitDescribe>
                </configuration>

            </plugin>
            <!-- END OF GIT COMMIT ID PLUGIN CONFIGURATION -->

            <!-- other plugins -->
        </plugins>
    </build>
</project>

git.properties in /src/main/resources:

git.commit.id=${git.commit.id}

Viewing the Commit History, By default, with no arguments, git log lists the commits made in that repository in reverse chronological order; that is, the most recent commits show up first. detached checkout with symbolic link HEAD d1a43f2 - reset --hard/read-tree -- reset� $ git log commit ca82a6dff817ec66f44342007202690a93763949 Author: Scott Chacon <schacon@gee-mail.com> Date: Mon Mar 17 21:52:11 2008 -0700 Change version number

You can use maven-buildnumber-plugin, which supports Git among a few other SCM systems.

It also has additional feature related to generating unique build number, besides just getting revision/commit ID: figure out SCM branch, add timestamps, use short hashes, etc.

git-show Documentation, It also presents the merge commit in a special format as produced by git diff-tree --cc. Enable the heuristic that shifts diff hunk boundaries to make patches easier to read. Output only the last line of the --stat format containing total number of� Note: I have shown you the last commit only. You will get a sequence of commits in reverse chronological order. As you can see, there is an additional line printed on the console called log size and a number. So, this number is the commit message length in bytes. It is required by various tools that read commit message through git log command

I tried to use with Spring Boot and line git.commit.id=${git.commit.id} didn't work. I had to use git.commit.id=@git.commit.id@

Revision Selection, Now you'll explore a number of very powerful things that Git can do that you may not For example, to examine a specific commit where you know you added� $ git reset --hard HEAD~1. In case you're using the Tower Git client, you can simply hit CMD+Z to undo the last commit: You can use same, simple CMD+Z keyboard shortcut to undo many other actions, from a failed merge to a deleted branch! Undoing Multiple Commits. The same technique allows you to return to any previous revision: $ git reset

How to Retrieve Hash for Commits in Git, Git allows recovering wrong changes in a project. This tutorial shows how to find information about the latest commit and get the latest commit's hash. This combination immediately creates a commit of all the staged changes and takes an inline commit message. Amend your last commit. Git has a number of awesome features; Not least of all is the

How can I undo the last commit?, Git's amend feature. It allows you to correct the last commit's message as well as add more changes to it. If that's what you want to do, read more about amend. git commit -am “My new changes” The output in your terminal should look something like this: [master 22gc8v1] My new message 1 file changed, 1 insertion(+) Using detailed commit messages. Although git commit -m "commit message" works just fine, it can be useful to provide more detailed and systmatic information.

How to Undo the Last Commit. In this post I will show how I…, Feb 20, 2018 � 3 min read. Image for root@debian:/home/debian/test-project# git checkout <commit hash> If you wish to undo/revert the last commit you can do the following, using the commit hash that you get from the git log command: To Git, it will look like a brand new commit. All you have to do is stage the extra changes like you would for a normal commit in git. So let’s update the last commit in real time with the example: Step 1: You have the file edited and now we have to first add the file. git add . Step 2: And then just commit with the --amend argument. git

Comments
  • does this file gets auto generated? Or do I explicitly put it in resources?
  • @NisargPatil I'm not sure what file you refer to, but no, this does not create any files. git.properties was just an example.