Archive for May, 2017

Git rename branch

Rename a local and remote branch in git

If you have named a branch incorrectly AND pushed this to the remote repository follow these steps before any other developers get a chance to jump on you and give you shit for not correctly following naming conventions.

1. Rename your local branch.
If you are on the branch you want to rename:

1
git branch -m new-name

If you are on a different branch:

1
git branch -m old-name new-name

2. Delete the old-name remote branch and push the new-name local branch.

1
git push origin :old-name new-name

3. Reset the upstream branch for the new-name local branch.
Switch to the branch and then:

1
git push origin -u new-name
Advertisements

Leave a comment

create directory and file

/**
* Create directory and file if not exists
*/
public File createDirectory() throws IOException {
File file = new File(“C:\\report”);
if (!file.exists()) {
file.mkdir();
}

file = new File(“C:\\report\\report.xls”);
if (!file.exists()) {
file.createNewFile();
}
return file;
}

 

Leave a comment

Git History

Goals

  • To learn to view the project’s history.

Getting a list of changes made is a function of the git log command.

RUN:

git log

You will see …

RESULT:

$ git log
commit fa3c1411aa09441695a9e645d4371e8d749da1dc
Author: Alexander Shvets <alex@githowto.com>
Date:   Wed Mar 9 10:27:54 2011 -0500

    Added HTML header

commit 8c3228730ed03116815a5cc682e8105e7d981928
Author: Alexander Shvets <alex@githowto.com>
Date:   Wed Mar 9 10:27:54 2011 -0500

    Added standard HTML page tags

commit 43628f779cb333dd30d78186499f93638107f70b
Author: Alexander Shvets <alex@githowto.com>
Date:   Wed Mar 9 10:27:54 2011 -0500

    Added h1 tag

commit 911e8c91caeab8d30ad16d56746cbd6eef72dc4c
Author: Alexander Shvets <alex@githowto.com>
Date:   Wed Mar 9 10:27:54 2011 -0500

    First Commit

Here is a list of all the four commits to the repository, which we were able to make so far.

01One line history

You fully control over what the log shows. I like the single line format:

RUN:

git log --pretty=oneline

You will see …

RESULT:

$ git log --pretty=oneline
fa3c1411aa09441695a9e645d4371e8d749da1dc Added HTML header
8c3228730ed03116815a5cc682e8105e7d981928 Added standard HTML page tags
43628f779cb333dd30d78186499f93638107f70b Added h1 tag
911e8c91caeab8d30ad16d56746cbd6eef72dc4c First Commit

02Controlling the display of entries

There are many options to choose which entreis appear in the log. Play around with the following parameters:

git log --pretty=oneline --max-count=2
git log --pretty=oneline --since='5 minutes ago'
git log --pretty=oneline --until='5 minutes ago'
git log --pretty=oneline --author=<your name>
git log --pretty=oneline --all
git log -- [filename]

Leave a comment