Pagine

Tuesday 4 July 2017

maven-assembly-plugin error: No formats specified in the execution parameters or the assembly descriptor

Build Error log:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:55 min
[INFO] Finished at: 2017-07-03T09:37:42+02:00
[INFO] Final Memory: 186M/444M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.4.1:single (default) on project mycomponent: No formats specified in the execution parameters or the assembly descriptor. -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :mycomponent
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:39 min
[INFO] Finished at: 2017-07-03T09:37:43+02:00
[INFO] Final Memory: 17M/90M
[INFO] ------------------------------------------------------------------------

Solution:

The maven-assembly-plugin version 2.4.1 is affect of a bug. I found the following apache issue jira in https://issues.apache.org/jira/browse/FALCON-1898. This is issue regards the version 2.6 but I think the same bug. You can use an other plugin version, I used the version 2.2 to fix it. 

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.2</version>
    <executions>
       .....
    </executions>
</plugin>   

Monday 3 July 2017

Maven compilation error - java.lang.IllegalStateException: endPosTable already set

Error stack trace:

java.lang.IllegalStateException: endPosTable already set
        at com.sun.tools.javac.util.DiagnosticSource.setEndPosTable(DiagnosticSource.java:136)
        at com.sun.tools.javac.util.Log.setEndPosTable(Log.java:350)
        at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:667)
        at com.sun.tools.javac.main.JavaCompiler.parseFiles(JavaCompiler.java:950)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.<init>(JavacProcessingEnvironment.java:892)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.next(JavacProcessingEnvironment.java:921)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1187)
        at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
        at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856)
        at com.sun.tools.javac.main.Main.compile(Main.java:523)
        at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)
        at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)
        at org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess(JavaxToolsCompiler.java:125)
        at org.codehaus.plexus.compiler.javac.JavacCompiler.performCompile(JavacCompiler.java:169)
        at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:823)
        at org.apache.maven.plugin.compiler.TestCompilerMojo.execute(TestCompilerMojo.java:153)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
    [INFO] -------------------------------------------------------------
    [ERROR] COMPILATION ERROR : 
    [INFO] -------------------------------------------------------------
    [ERROR] An unknown compilation problem occurred
    [INFO] 1 error
    [INFO] -------------------------------------------------------------
    [INFO] ------------------------------------------------------------------------
    [INFO] Reactor Summary:

Solution:

A better solution is the usage of useIncrementalCompilation option in compiler plugin configuration as below:
    <plugin>         <groupId>org.apache.maven.plugins</groupId>         <artifactId>maven-compiler-plugin</artifactId>         <version>${maven-compiler-plugin.version}</version>         <configuration>           <compilerVersion>1.8</compilerVersion>           <source>1.8</source>           <target>1.8</target>           <useIncrementalCompilation>false</useIncrementalCompilation>           <compilerArgs>             <arg>-Xlint:deprecation</arg>             <arg>-Xlint:unchecked</arg>           </compilerArgs>         </configuration>     </plugin>

Technology stack:

  • Apache Maven 3.3.9
  • Jdk 1.8.0_73

Friday 30 June 2017

Comparison of Subversion clients

There are several subversion clients as TortoiseSVN, SmartSVN, RabbitVCS, VisualSVN, AnkhSVN, etc... Choose the better svn client is not easy because it depends from the usage you want to do and the other softwares related.
The goal of this short article is to make a brief overview of some of the clients in circulation highlighting the relevant terms for each of them. 

TortoiseSVN

TortoiseSVN implements a Windows shell extension (linux version is not available), it is easy to use, since it doesn't require the Subversion command line client to run. About the license It is a free tool (GPL).
TortoiseSVN's official web page: https://tortoisesvn.net/

SmartSVN

SmartSVN is a client avaible for OS X, Linux and Windows. It provides a good user interface. About the license, there are two versions: free Foundation edition and as full-featured Professional edition. 
SmartSVN's official web page: http://www.smartsvn.com/

RabbitVCS

RabbitVCS is a set of graphical tools for linux written to provide simple and straightforward access to the version control systems you use. It is not only svn client but even for others source version controls, for example Git. About the licence, it is an other free tool (GPL). You can see some screenshoot in this page.
RabbitVCS's official web page: http://rabbitvcs.org/

VisualSVN

VisualSVN is a professional grade svn integration plug-in for Visual Studio. I think that this plug-in is mandatory if you use svn and Visual Studio.  About the licence, there are more versions also free versions, all details are described in this page. You can see some screenshoot in this page.
VisualSVN's official web page: https://www.visualsvn.com/visualsvn/

AnkhSVN

AnkhSVN is an other Subversion Source Control Provider for Microsoft Visual Studio 2005-2015 and 2017.  About the licence, it is an other free tool but with Apache Licence. You can see some screenshoot in this page.
AnkhSVN's official web page: https://ankhsvn.open.collab.net/

Thursday 29 June 2017

Eclipse SVN Subclipse vs Subversive plugin

The SVN people have developed a plugin called Subclipse. The Eclipse people have a plugin called Subversive.
Subclipse includes the CollabNet Merge Client originally developed as part of the CollabNet Desktop - Eclipse Edition. The CollabNet Merge Client provides powerful graphical merge capabilities that leverages the merge tracking functionality that was added as part of the Subversion 1.5 release.
Subclipse includes an optional Mylyn connector that enables Mylyn to create automatic changesets based on the tasks you are working on. It also enables links to tasks when viewing history of Subversion commits.
You can see the Subclipse's screenshots in this page.

Instead Subversive have a few convenient features as:

  • Full-Scale SVN Client
  • Seamless Integration with Eclipse
  • Advanced SVN Features
  • Support of the Latest SVN Versions
You can see the Subversive's screenshots in this page.

Functionally the products are very similar as both are mature products.

Monday 26 June 2017

Cloud service models – IaaS, PaaS, and SaaS

There are three cloud-based service models, IaaS, PaaS, and SaaS. The main features of each of these are listed here:
  • Infrastructure as a Service (IaaS) provides users the capability to provision processing, storage, and network resources on demand. The customers deploy and run their own applications on these resources. Using this service model is closest to the traditional in-premise models and the virtual server provisioning models (typically offered by data center outsourcers). The onus
    of administering these resources rests largely with the customer.
  • In Platform as a Service(PaaS), the service provider makes certain core components, such as databases, queues, workflow engines, e-mails, and so on, which are available as services to the customer. The customer then leverages these components for building their own applications. The service provider ensures high service levels, and is responsible for scalability, highavailability, and so on for these components. This allows customers to focus a lot more on their application's functionality. However, this model also leads to application-level dependency on the providers' services.
  • In the Software as a Service(SaaS) model, typically, third-party providers using a subscription model provide end-user applications to their customers. The customers might have some administrative capability at the application level, for example, to create and manage their users. Such applications also provide some degree of customizability, for example, the customers can use their own corporate logos, colors, and many more. Applications that have a very wide user base most often operate in a self-service mode. In contrast, the provider provisions the application for the customer for more specialized applications. The provider also hands over certain application administrative tasks to the customer's application administrator (in most cases, this is limited to creating new users, managing passwords, and so on through well-defined application interfaces).
From an infrastructure perspective, the customer does not manage or control the underlying cloud infrastructure in all three service models.
The diagram illustrates who is responsible for managing the various components of a typical user application across IaaS, PaaS, and SaaS cloud service models. The column labeled Private represents the main components of a user application stack, while the following columns depict the varying levels of management responsibilities in each of the three service models. The shaded boxes are managed by the service provider, while the unshaded boxes are managed by the user.
The level of control over operating systems, storage, applications, and certain network components (for example, load balancers) is the highest in the IaaS model, while the least (or none) in the SaaS model.

Friday 23 June 2017

What is cloud computing?

Wikipedia defines cloud computing as:
 "Cloud computing is internet-based computing in which large groups of remote servers are networked to allow the centralized data storage, and online access to computer services or resources."
The National Institute of Standards and Technology (NIST) gives the following definition of cloud computing:
"Cloud computing is a model for enabling convenient, on-demand network access to a shared pool of configurable computing resources (e.g., networks, servers, storage, applications, and services) that can be rapidly provisioned and released with minimal management effort or service provider interaction."
 
There are several other broadly accepted definitions of cloud computing. Some explicitly emphasize configurability of the resources, while others include the need for rapid on-demand provisioning of resources, and still others drop the requirement of access via the internet. We define cloud computing as a model that enables the features listed here:
  • Users should be able to provision and release resources on-demand;
  • The resources can be scaled up or down automatically, depending on the load;
  • The provisioned resources should be accessible over a network;
  • Cloud service providers should enable a pay-as-you-go model, where customers are charged based on the type and quantum of  resources they consume.
Some of the implications of choosing to use the cloud for your computing needs are as follows:
  • The illusion of infinite processing and storage resources, available on-demand, reduces the need for detailed advance planning and procurement processes. 
  • The model promotes the use of resources as per customer needs, for example, starting small, and then increasing resources based on an increase in need. 
  • The development and test environments can be provisioned on a smaller scale than production environment, and enabled only during normal business hours, to reduce costs.
  • The staging environment can be provisioned for a short duration to be a replica of the production environment. This enables testing using production configuration (and scale) for improved defect resolution.
  • There will be ease of scaling, both vertically and horizontally, in order to better manage spikes in demand and variations due to business cycles or time-of-day reasons, and so on.
  • This encourages experimentation, by trying out new ideas and software by quickly  provisioning resources, rather than requisition for resources through time-consuming and cumbersome processes.
In addition, there are several key operational and maintenance-related implications, including no hardware maintenance or data center operations required, zero-downtime migrations and upgrades, ease of replacement of unhealthy machines, ease of implementation of high-availability and disaster recovery strategies, and many more.

Thursday 22 June 2017

What is GitHub?

GitHub is the leading code-hosting platform with literally millions of open source projects having their code hosted on it. In conjunction with Git, it provides the means for a productive development workflow and is the preferred tool among developers.

Starting with the basics of creating a repository, you can learn how to manage the issue tracker, where your project can be discussed.
GitHub provides a set of features as of example:
  • Managing wiki pages: When you first create a new repository, a wiki attached to this project is also created. It is enabled by default and everyone can add new content or modify existing pages. Every time you add one or more new pages to the wiki. Similarly you can edit or remove a wiki page.
  • Managing code versioning: the notion of a release is tightly tied to Git tags. You can see the existing tags, if any, from the same menu where you change a branch. Your tag name can be any arbitrary value, but it is highly recommended to follow the semantic versioning scheme. Briefly describing what semantic versioning is, a release number consists of three numbers separated by dots in the form of MAJOR.MINOR.PATCH. You should then increment the following:
    • The MAJOR version when you make incompatible API changes.
    • The MINOR version when you add functionality in a backwards-compatible manner.
    • The PATCH version when you make backwards-compatible bug fixes.
  • Organization and team management: GitHub allows you to choose among three roles for a person in an organization: owners, members, and billing managers. Owners have full access to the organization and are in the highest level of the permissions chain. Being a member is usually the default role when a new person gets in the organization. The least a member can do is create a new team and add existing team members and repositories to it. A billing manager is a user who manages the billing settings for your organization, such as updating payment information. This is a great option if regular members of your organization don't typically have access to billing resources. You can create an Organization and you can optionally invite some people to be part of the organization.
  • Pull requests feature (that made GitHub so well known): GitHub UI helps you visualize clearer what is about to be merged in the default branch or the branch of your choice. Pull requests are reviewable with an enhanced diff view. You can easily revert them with a simple button on GitHub and they can be tested before merging, if a Continuous Integration service is enabled in the project.
  • GitHub Pages: At the end of the year 2008, GitHub announced GitHub Pages, a static-site hosting service. Static sites have met a great rise during the past years and GitHub played a big part in it. A static site is a site that contains pages written in HTML, CSS, and Javascript. No server code, such as php, ruby, and Python is included.
  • User and Repository management: As a user, there is a lot of information you can set up in your user settings page, such as associating more than one e-mail to your account, adding multiple SSH keys, or setting up two-factor authentication. Similarly, some functionalities of a repository can be set up via its settings page. For example, you can enable or disable the wiki pages, or completely disable the issue tracker. About the repository management, there are quite a few settings one can fiddle with at the repository level. To access these settings, search for the wrench icon on the right sidebar.

Monday 19 June 2017

How to manage offline and online mode in your JFrog Artifactory

JFrog Artifactory supports two kind of offline cases: when the whole organization is disconnected from remote repositories and when one or more remote repositories needs to be put offline.
When the artifactory server (or single repo) is not possible the artifact downloads from remote repositories as maven repository (https://mvnrepository.com/).
It is possible to set your JFrog Artifactory in "Global Offline Mode" via Admin Console Web. In detail, select Admin -> Configuration -> General and flag the checkbox with label "Global Offline Mode". See the screenshot below:

Only an user with admin grant can set on/off this mode. Of course when "Global Offline Mode" is enabled, options online/offline on individual repositories are not considered because all repositories
become offline.
Instead, you can configure your artifactory server online and some repositories offline. In this case, select Admin -> Repositories -> Remote, choose the repository and flag the checkbox with label "Offline". See the screenshot below:
Again, you need a user with admin grant can set on/off this mode.

Thursday 15 June 2017

What is devOps?

DevOps is, by definition, a field that spans several disciplines. It is a field that is very practical and hands-on, but at the same time, you must understand both the technical background and the nontechnical cultural aspects.
The word "DevOps" is a combination of the words "development" and "operation". This wordplay already serves to give us a hint of the basic nature of the idea behind DevOps. It is a practice where collaboration between different disciplines of software development is encouraged.
The origin of the word DevOps and the early days of the DevOps movement can be tracked rather precisely: Patrick Debois is a software developer and consultant with experience in many fields within IT. He was frustrated with the divide between developers and operations personnel. He tried getting people interested in the problem at conferences, but there wasn't much interest initially.
In 2009, there was a well-received talk at the O'Reilly Velocity Conference: "10+ Deploys per Day: Dev and Ops Cooperation at Flickr." Patrick then decided to organize an event in Ghent, Belgium, called DevOpsDays. This time, there was much interest, and the conference was a success. The name "DevOpsDays" struck a chord, and the conference has become a recurring event. DevOpsDays was abbreviated to "DevOps" in conversations on Twitter and various Internet forums.
The DevOps movement has its roots in Agile software development principles. The Agile Manifesto was written in 2001 by a number of individuals wanting to improve the then current status quo of system development and find new ways of working in the software development industry. The following is an excerpt from the Agile Manifesto, the now classic text, which is available on the Web at http://agilemanifesto.org/:
"Individuals and interactions over processes and tools
Working software over comprehensive documentation
Customer collaboration over contract negotiation
Responding to change over following a plan
That is, while there is value in the items on the right, we value the items on the left more."
In light of this, DevOps can be said to relate to the first principle, "Individuals and interactions over processes and tools."
This might be seen as a fairly obviously beneficial way to work—why do we even have to state this obvious fact? Well, if you have ever worked in any large organization, you will know that the opposite principle seems to be in operation instead. Walls between different parts of an organization tend to form easily, even in smaller organizations, where at first it would appear to be impossible for such walls to form.
DevOps, then, tends to emphasize that interactions between individuals are very important, and that technology might possibly assist in making these interactions happen and tear down the walls inside organizations. This might seem counterintuitive, given that the first principle favors interaction between people over tools, but my opinion is that any tool can have several effects when used. If we use the tools properly, they can facilitate all of the desired properties of an Agile workplace.
A very simple example might be the choice of systems used to report bugs. Quite often, development teams and quality assurance teams use different systems to handle tasks and bugs. This creates unnecessary friction between the teams and further separates them when they should really focus on working together instead. The operations team might, in turn, use a third system to handle requests for deployment to the organization's servers.
An engineer with a DevOps mindset, on the other hand, will immediately recognize all three systems as being workflow systems with similar properties. It should be possible for everyone in the three different teams to use the same system, perhaps tweaked to generate different views for the different roles. A further benefit would be smaller maintenance costs, since three systems are replaced by one.
Another core goal of DevOps is automation and Continuous Delivery. Simply put, automating repetitive and tedious tasks leaves more time for human interaction, where true value can be created.

Monday 12 June 2017

How to resolve some git errors

This post will help the readers a lot because the errors mentioned can occur very frequently.

Remote origin already exists

This error occurs when you already have a remote repository specified and the remote origin removed and added. Example:
$ git remote rm origin
$ git remote add origin https://gitserver.com/scm/myproject.git

Git push fails with rejected error

This error occurs because you didn't execute git pull before git push. Example:
$ git pull
$ git push

Git push fails caused by "fatal: The remote end hung up unexpectedly"

This one is common and you should check whether your remote URL is correct and Git has access to the remote repository. I suggest add (if not already setted) the origin; else set the correct origin.

Restoring a changed file to its last committed state

Run git checkout followed by the filename and you will lose your changes. However, this will be restored as a clean copy of the file. Example:
$ git checkout fileName

Unstaging a file

Did you run git add too soon? Run git reset HEAD followed by the filename to unstage it:
$ git reset HEAD fileName

How to fix the most recent commit message

The –amend option will edit a commit message:
$ git commit --amend
The editor will open to edit the last message.

Reset the most recent commit

There are two ways to do this: with and without your changes.
1) Without losing changes:
$ git reset HEAD~1
2) By losing changes:
$ git reset --hard HEAD~1

I found a bug after releasing the product but it was in the commit that I did a long time ago

In this case, you should not use git reset because it rewrites the history and the product is already released. Therefore, you should make a commit that reverts the buggy commit and pushes it to
share with your colleagues:
$ git revert 17cc9433abcf23c42aef6b9aad24b5fcfc353f7c

There are many garbage files in the working directory. How to delete them?

In this situation, the files are not maintained by Git, so you have to use git clean:
1) To check the files that will be removed
$ git clean -n
2) Now remove them:
$ git clean -f

I think I made a mistake while resolving conflicted files. How do I restore it to the state just after git merge?

To do this, you can use git checkout:
$ git checkout --merge fileName

Gitindex file is corrupt

No need to worry. This one is rare but can be annoying! Git will display the error as "bad index file sha1 signature: fatal: index file corrupt". You just have to remove the backup index file; remove it, and then reset the repository:
$ mv .git/index .git/indexOLD

$ git reset

Git refuses to start a merge/pull command.

The typical error messages look like this:
  • Error: The myfile.txt entry is not up to date; it cannot be merged.
  • Error: The myfile.txt entry will be overwritten by the merge command.
To resolve this, perform the following steps:
1. Stash the changes or throw them out:
$ git stash save "a message"
$ git checkout myfile.txt
2. Check that the changes are staged:
$ git status
3. Bring the changes from the remote repository:
$ git pull
4. Repopulate if you made a stash:
$ git stash pop

Friday 9 June 2017

How to use git bisect

The git bisect command allows you to run a binary search through the commit history to find a commit that has an issue. For example, you pulled the last commits and the website isn't working anymore. You know that before the last pull everything was okay. So you have to find the commit ID before it crashes and the last ID after the pull:
$ git bisect start
$ git bisect bad <commit_id_after_pull>
$ git bisect good <commit_id_before_pull>
Now, the bisecting loop begins and Git will check for an alternative commit.
Reset the given commit and tell Git whether the website is working:
$git bisect <bad_commit_id>
Git will search again and again to find which commit crashed the website:
$ git show <commit_id>
Instead of trying to locate a bug inside all your files, you have a shortened list of files.

How to reset a git commit via bash script 

If you don't want to reset to a given commit and test your software, you can create a bash script and tell Git to use it. The script has to return 0 if the condition is fulfilled, and nonzero if it isn't.
check_file.sh

#!/bin/bash
FILE=$1
If [ -f $FILE];
then
    exit 0;
else
    exit 1;
fi
Now it's time to run git bisect to specify the last 10 commits:
$ git bisect start HEAD HEAD~10
$ git bisect run ./check_file.sh MyFile.java

Bisect algorithm

The algorithm used by git bisect always returns the commit that is at the middle position of the array.
In the following diagram, you will see how the algorithm found the good commit in three steps:
  1. The Commit6 option is selected by Git. After checking it, you tell Git that it's good.
  2. Git reduces the array because if Commit6 is good, then every commit between Commit1 and Commit6 is good too.
  3. Then Git asks you to test Commit9, and you say that it's good too.
  4. So the error can only be inside Commit10 and Commit11.

Thursday 8 June 2017

How to solving merge conflits with git

When you are working with several branches, a conflict will probably occur while merging them. It appears if two commits from different branches modify the same content and git isn't able to merge them. If it occurs, Git will mark the conflict and you have to resolve it.
For example, Developer1 modified the myfile.txt on a feature branch and Developer2 has to edit it on another branch. When Developer2 merges the two branches, the conflict occurs.
Git will tell you to edit the file to resolve the conflict. In this file, you will find the following:
<<<<<<< HEAD
Changes from Developer2
=======
Changes from Developer1
>>>>>>> 5df2fcdc89e0a33fcf8cbbbbd89cb8eabbdb61b7
The <<<<<<< characters indicate the start of the merge conflict, the ====== characters indicate the break points used for comparison, and >>>>>>> indicate the end of the conflict.
To resolve a conflict, you have to analyze the differences between the two changes and merge them manually. Don't forget to delete the signs added by Git. After resolving it, simply commit the changes.
If your merge conflict is too complicated to resolve because you can't easily find the differences, Git provides a useful tool to help you.
The "git diff" and "git mergetool" help you to find differences. Other tools to visually compare and merge files are:

Wednesday 7 June 2017

How to configure git alias

Git allows you to use aliases for command lines. The alias concept is similar to linux. Setup git alias is very fast: in your $HOME edit the .gitconfig file and add the following text:
[alias]
    l = log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short
Now if you run the following command:
$ git l
see the output of alias "l". Now you are ready to create a new customer alias or add other aliases available in web.

Examples of aliase are:

    l = log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short
    a = add    
    ap = add -p
    c = commit --verbose
    cm = commit -m
    cam = commit -a -m
    d = diff
    ds = diff --stat
    dc = diff --cached
    s = status -s
    co = checkout
    cob = checkout -b
    cmp = "!f() { git add -A && git commit -m "$@" && git push; }; f"
    la = "!git config -l | grep alias | cut -c 7-"

Tuesday 6 June 2017

How to rewrite commit history with git

Someone accidentally commits a huge binary file with a thoughtless git add ., and you want to remove it everywhere. Perhaps you accidentally committed a file that contained a password, and you want to make your project open source. filter-branch is the tool you probably want to use to scrub your entire history. The --tree-filter option runs the specified command after each checkout of the project and then recommits the results. 

Examples:

1) To remove a file named mypasswords.txt from your entire history, you can use the --tree-filter option to filter-branch: 
$ git filter-branch --tree-filter 'rm -f mypasswords.txt' HEAD
Rewrite 802a096d79b9b5872544a6b35d6a52cbdf55274a (21/21)
Ref 'refs/heads/master' was rewritten 
2) If you want to remove all accidentally committed editor backup files, you can run something like
$ git filter-branch --tree-filter 'rm -f *~' HEAD.

--index-filter option

The --index-filter is another option similar to the tree filter but does not check out the tree, which makes it much faster.
$ git filter-branch --index-filter 'git rm --cached --ignore-unmatch myfilename.txt' HEAD
The --ignore-unmatch option is needed because "git rm" will fail if the file is absent from the tree.

Monday 5 June 2017

Canceling a commit with git

The git revert command allows you to cancel your last unpushed commit. The type of cancel is only logical because Git doesn't drop phisically the commit but it creates a new commit that executes the opposite of your commit. A pushed commit is irreversible, so you cannot change it.

Example

The following example illustrates how to remove last pushed commit. First step, let's have a look at the last commits:
$ git log
commit dc2d9f3deda6f49902c1879b7b861fac51683865
Author: infoamodomio <infoamodomio@infoamodomio.com>
Date:   Thu May 25 12:19:01 2017 +0200
    Added a new file
Second step, We want to cancel the dc2d9f… commit:
$ git revert dc2d9f
Canceling this commit isn't necessary to enter the full commit ID, but just the first characters. Git will find it, but you will have to enter at least six characters to be sure that there isn't another commit that starts with the same characters.

Thursday 1 June 2017

How to edit a commit with git

It is possible three actions to edit a commit:
  1. Change the comment;
  2. Add one or more files in a commit;
  3. Remove one or more files in a commit.

Examples

1) If you want to edit the description of your last commit, use the following line: 
 $ git commit --amend
2) Let's suppose that your last commit contains buggy code; you can specify that your changes on the file are part of the last commit:
 $ git add file.txt
 $ git commit -v -amend
3) Now I want to remove a file I included accidentally in the last commit (because this file deserves a new commit):
 $ git reset HEAD^1 file.txt
 $ git commit --amend -v
 $ git commit -v file.txt

Wednesday 31 May 2017

Learning maven classifier with examples

The classifier allows to distinguish artifacts that were built from the same POM but differ in their content. It is some optional and arbitrary string that - if present - is appended to the artifact name just after the version number.
A common use case for classifiers is the need to attach secondary artifacts to the project's main artifact. If you browse the Maven central repository, you will notice that the classifiers sources and javadoc are used to deploy the project source code and API docs along with the packaged class files.

Example:

The following dependency refers to my-artifact-1.0.jar
<dependency>
    <groupId>it.blogspot.informaticaamodomio</groupId>
    <artifactId>my-artifact</artifactId>
    <version>1.0</version>
</dependency>
The following dependency refers to my-artifact-1.0.source.jar
<dependency>
    <groupId>it.blogspot.informaticaamodomio</groupId>
    <artifactId>my-artifact</artifactId>
    <version>1.0</version>
    <classifier>sources</classifier>
</dependency>
The following dependency refers to my-artifact-1.0.javadoc.jar
<dependency>
    <groupId>it.blogspot.informaticaamodomio</groupId>
    <artifactId>my-artifact</artifactId>
    <version>1.0</version>
    <classifier>javadoc</classifier>
</dependency>
Another example, we suppose we have two jars with the same artifact id (my-artifact) but different group id as below:
<dependency>
    <groupId>it.blogspot.informaticaamodomio</groupId>
    <artifactId>my-artifact</artifactId>
    <version>1.0</version>
</dependency>

<dependency>
    <groupId>com.othercompany</groupId>
    <artifactId>my-artifact</artifactId>
    <version>1.0</version>
</dependency>
Both jars have following name: my-artifact-1.0.jar. The use of classifier can be helpful:
 <dependency>
    <groupId>it.blogspot.informaticaamodomio</groupId>
    <artifactId>my-artifact</artifactId>
    <version>1.0</version>
    <classifier>info</classifier>
</dependency>
So in this case the jar name is "my-artifact-1.0.info.jar" in this way simplifying the distinction between the two jars.

Monday 29 May 2017

How to use the git reset command

The git reset command will allow you to go back to a previous state (for example, commit). The git reset command has three options (soft, hard, or mixed, by default). In general, the git reset command's aim is to take the current branch, reset it to point somewhere else, and possibly bring the index and work tree along. 
This means that
 git reset <paths>
is the opposite of
 git add <paths>
More concretely, if the master branch (currently checked out) looks like the first row (in the following figure) and you want it to point to B and not C, you will use this command:
 git reset B
The more options that you can provide on the reset command can be easily explained:
  • --hard: This option is the simplest. It will restore the content to the given commit. All the local changes will be erased. The git reset --hard command means git reset --hard HEAD, which will reset your files to the previous version and erase your local changes.
  • --mixed: This option resets the index, but not the work tree. It will reset your local files, but the differences found during the process will be marked as local modifications if you analyze them using git status. It's very helpful if you make some bugs on previous commits and want to keep your local changes.
  • --soft: This option will keep all your files, such as mixed, intact. If you use git status, it will appear as changes to commit. You can use this option when you have not committed files as expected, but your work is correct.
  • --merge: this option resets the index and updates the files in the working tree that are different between <commit> and HEAD, but keeps those which are different between the index and working tree (i.e. which have changes which have not been added). If a file that is different between <commit> and the index has unstaged changes, reset is aborted. In other words, --merge does something like a git read-tree -u -m <commit>, but carries forward unmerged index entries.
  • --keep: this options resets index entries and updates files in the working tree that are different between <commit> and HEAD. If a file that is different between <commit> and HEAD has local changes, reset is aborted.
The git reset command doesn't remove untracked files; use git clean instead.

Examples

1) Undo add:
 $ git add myfile.txt
 $ git reset
2) Undo a commit and redo:
 $ git commit -m "a comment"
 $ git reset --soft HEAD^
 $ git commit -a -c ORIG_HEAD
3) Undo a commit, making it a topic branch:
 $ git branch atopicbranch    
 $ git reset --hard HEAD~3  
 $ git checkout atopicbranch
4) Undo commits permanently:
 $ git commit ...
 $ git reset --hard HEAD~3
5) Undo a merge or pull:
 $ git pull
 Auto-merging ...
 CONFLICT (content): Merge conflict in ...
 Automatic merge failed; fix conflicts and then commit the result.
 $ git reset --hard
 $ git pull . atopicbranch
 Updating from 81683... to 43984...
 Fast-forward
 $ git reset --hard ORIG_HEAD
6) Undo a merge or pull inside a dirty working tree:
 $ git pull
 Auto-merging ....
 Merge made by recursive.
  ...                |   20 +++++----
  ...
 $ git reset --merge ORIG_HEAD
7) Interrupted workflow:
 $ git checkout feature ;
...developement...
 $ git commit -a -m "snapshot"
 $ git checkout master
...bug fixing...
 $ git commit 
 $ git checkout feature
 $ git reset --soft HEAD^ ;# go back to before bug fixing 
 $ git reset
8) Keep changes in working tree while discarding some previous commits:
 $ git tag 1.0
 $ git checkout -b branch1
... edit one o more files...
 $ git commit -m "a comment"
... edit one o more files...
 $ git checkout -b branch2
 $ git reset --keep 1.0
9) Split a commit apart into a sequence of commits:
 $ git reset -N HEAD^
 $ git add -p
 $ git diff --cached
 $ git commit -c HEAD@{1}
...
 $ git add file.txt
 $ git diff --cached
 $ git commit -m "a comment"

Friday 26 May 2017

How to revert uncommitted changes with git

Let's suppose you edited a file on the production working directory, but didn't commit it. On your last push, you edited it, and the changes in production aren't needed anymore. So, your goal is to erase changes on this file and reset the file to the last committed version:
$ git checkout myfile.txt
This command is really nice if you want to restore a deleted file. You can also specify a commit pointer to use (useful if you stash [1] your changes):
$ rm myfile.txt
$ git checkout HEAD myfile.txt

Link

[1] Stashing your changes with git

Thursday 25 May 2017

Stashing your changes with git

Git has a command that allows you to save the current state of the local working repository and go back to the last committed revision with git stash. This is really helpful when you have to develop an urgent fix. After this, you can restore the stashed changes and continue with your development.
To use this command, just execute the following command snippet:
$ git stash
Do your fix and then unstash edit:
$ git stash pop
Of course, you can do more with this command, such as save a list of stashes:
$ git stash
See the list of available stashes
$ git stash list
Apply the second stash
$ git stash apply stash@"1}
Delete a stash
$ git stash drop stash@"1}
Or delete all stashes
$ git stash clear
Let's suppose that your stash concerns a feature and you haven't created a dedicated branch for it. You can simply create a branch executing this command:
$ git stash branch mynewbranch
Remember this command is only for urgent fixes. If you want to add a new feature, you should use a new branch.

Wednesday 24 May 2017

How to use the Cherry-pick git command

The cherry-pick git command lets you select a commit from a branch to apply it to another. The patch will be considered as a new commit in the selected branch.
The synopsis is:
git cherry-pick <id_commit>

Example

Let's try to understand this by exploring the following example: Developer1 creates the deve1 branch from master and adds a new file in it:
$ touch file.txt
$ git add file.txt
$ git commit -m 'add file.txt'
$ echo "new line" > file.txt
$ git commit -a -m 'updated file.txt'
As you can see, the developer creates the file.txt, adds it into Git, and commits it.Then he edits it and commits again. Now, let's see the commit history for this branch.
$ git log --oneline
5f8ed47 add file.txt
44c67b9 updated file.txt
Now, the developer will apply the first commit to the master branch:
$ git checkout master
$ git cherry-pick 44c67b9 
Let's imagine that the cherry-pick went wrong and the developer wants to abort it:
$ git cherry-pick --abort 
However, if you want to roll back a cherry-pick, you have two ways to do it:
  • If it's in a private branch, you can use the git rebase command.
  • If it's already in a public branch, use the git revert command.

Tuesday 23 May 2017

Git - rebase vs merge

The merge command combines the changes from two branches. Instead the rebase command will take the changes from the first branch and apply them to the other branch.

The rebase command can be used if you want to get a feature (commits) from one branch to another and be sure to be close to the tip of the upstream branch. The command applies the changes from the branch called branch to the master branch.

The following examples show the usage of these two commands.

Example of merge:
$ git checkout mybranch
$ git merge master
Example of rebase:
$ git checkout mybranch
$ git rebase master
Note: In the rebase command do not merge commit.

Monday 22 May 2017

How to create a patch with git

When a developer to make small fixes in a part of the project, but he didn't want to give him access to the repository. In this scenario the developer can create a git patch and send it via mail.
The following command will create .patch files per commit:
$ git format-patch origin patch-myproject.patch
Later you can send the patch by mail:
$ git send-email patch-myproject.patch
The patch can be imported with by executing this:
$ git apply /tmp/patch-myproject.patch
This command will apply the patch, but it doesn't create commits. So, to generate a series of commits, use the git am command:
$ git am /tmp/patch-myproject.patch

Friday 19 May 2017

How to removing a file with git

If you don't want a file anymore, there are two ways to remove it. First mode: delete the file manually and commit the changes. This will delete the file locally and on the repository. Use the following command line:
$ rm myfile.txt
$ git commit -m 'delete the file with name: myfile.txt'
Second mode: delete the file only through git:
$ git rm --cached myfile.txt

Thursday 18 May 2017

Git - fatal: refusing to merge unrelated histories

During a merge between two branches, if the following error is returned:
$ git branch
* master
develop
$ git merge develop
fatal: refusing to merge unrelated histories
Error redoing merge <version-id>
Retry with the following option:
$ git merge develop --allow-unrelated-histories
This option is used in a rare event that merges histories of two projects that started their lives independently.

Monday 15 May 2017

How to revert a commint with svn

Yuo can revert one a more commits with the following command:
 svn merge -r <current_version>:<target_version> <folder>
After that you can commit the revert.

Example:

 svn merge -r 305:298 .
 svn commit -m "revert..."

Thursday 11 May 2017

How to migrate a branch in a new git repository

For a reason with almost zero probability but not impossible you may find yourself in the situation of having to migrate a single branch between two git repositories.
Follow these steps for migration:
 git clone <old_repo>
 git checkout <branch_target>
 git remote set-url origin <new_repository>
 git push origin <branch_target>
Now clean your workspace, clone the old repository and remove branch target.
See the previous post "How to delete local and remote branches with git" for more details about delete of a branch.

Tuesday 9 May 2017

How to change svn user in TortoiseSVN client (Windows)


TortoiseSVN is a Subversion Client for Windows. After first svn checkout it requires the credentials to be stored. These credential is used for future operations (update, commit, etc...). If you use a second repository but a different svn account, TortoiseSVN uses automatically the credentials already stored and you will probably have an error access (403 forbidden).
The soluntion is the following:
  1. Right click
  2. TortoiseSVN
  3. Settings
  4. Saved Data
  5. Authentication data - Clear
  6. Svn operation (update, commit, etc...)
  7. Put new credentials

Monday 8 May 2017

Svn Error: E155036 - When it happens

The svn error with code "E155036" is thrown when you use a local copy created before an upgrade of svn server.
A typical scenario is the following:
  1. A developer creates his local copy.
  2. SVN Admin performs the svn server upgrade
  3. After the upgrade, the developer tries to use his local copy and svn throws the error "E155036".
The solution is very easy and it is shown in error description but the focus of this post is on the scenario just described.

> svn status
svn: E155036: Please see the 'svn upgrade' command
svn: E155036: Working copy '/home/user/myproject' is too old (format 10, create
d by Subversion 1.6)
> svn upgrade
Upgraded '.'
Upgraded 'A'
Upgraded 'A/B'
Upgraded 'A/B/C'
.... 

Friday 5 May 2017

How to rename a tag with git

The tag rename operation is not atomic but more steps are needed.
1) Create the tag with new name from old tag:
 git tag <new_tag> <old_tag>
2) Delete the old tag from local repository:
 git tag -d <old_tag>
3) Delete the old tag from remote repository:
 git push origin :refs/tags/<old_tag>
4) Push the local tag in remote repository:
 git push --tags
5) Lastly synchronize the tag list among local and remote repositories:
 git fetch -f

Thursday 4 May 2017

How to create a branch with git

Create a local branch from current branch:
 git checkout -b <new_branch>
Otherwise you can use the following command:
 git checkout -b <new_branch> <start_point>
where the start point can be an other branch or a tag.
Now if the new branch must become a remote branch then use also the following command:
 git push origin <new_branch>