Friday, 3 July 2015

Replacing CRLF with LF using Notepad++

a
In computing, a newline, also known as a line endingend of line (EOL), or line break, is a special character or sequence of characters signifying the end of a line of text. The actual codes representing a newline vary across operating systems, which can be a problem when exchanging text files between systems with different newline representations.
The concepts of line feed (LF) and carriage return (CR) are closely associated and can be either considered separately or lumped together. In the physical media of typewriters and printers, two axes of motion, "down" and "across", are needed to create another line (a new line) on the page. Although the design of a machine (typewriter or printer) must consider them separately, the abstract logic of software can lump them together as one event. This is why a newline in character encoding can be defined as LF and CR combined into one (LF+CR, LFCR, CR+LF, CRLF).

Software applications and operating systems usually represent a newline with one or two control characters:

So basically the most common one :

  • linux is LF (0x0a)
  • windows is CRLF (0x0d 0a)


Example:

I have a text file that has CRLF line terminators (which Windows uses to terminate lines) that I want to replace with LF line terminators (the UNIX way). Notepad++ demonstrates this rather well:

If you not seeing the CRLF, you can go to view -> Show Symbols -> Show End of Line /Show all characters
image
Notepad++’s Find/Replace feature handles this requirement quite nicely. Simply bring up the Replace dialog (CTRL+H), select Extended search mode (ALT+X), search for “\r\n” and replace with “\n”:
image
Hit Replace All (ALT+A)….and job’s a good’un:
image
Easy when you know how!!!

Amd there turns out there’s an even easier way. From Eugene in the comments below:
Another option is to go to Edit -> EOL Conversion -> Unix Format.

Git - how to change filename that has been committed

Q:
How does git handle filename changes?
Will a file name change be detected as a modification or will there be a "lost" file which needs to be removed and the new file needs to then be added with git add ?


A:
It will automatically be detected as a modification and the "new" file will be added to the index, so you only need one command:
$ git mv application.py newApplication.py
$ git status
# On branch buildServer
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       renamed:    application.py -> newApplication.py
And a commit of course ..

Git how to discard unstage/staged changes (original post)

1>For unstaged


You can use
git checkout -- file
You can do it without the -- (as suggested by nimrodm), but if the filename looks like a branch or tag (or other revision identifier), it may get confused, so using -- is best.
You can also check out a particular version of a file:
git checkout v1.2.3 -- file         # tag v1.2.3
git checkout stable -- file         # stable branch
git checkout origin/master -- file  # upstream master
git checkout HEAD -- file           # the version from the most recent commit
git checkout HEAD^ -- file          # the version before the most recent commit


Example: reset to most recent submit HEAD

user.name@PC_NAME /d/tem/git_sandpit/play1/123 (test123)
$ ls
readme1.txt

user.name@PC_NAME /d/tem/git_sandpit/play1/123 (test123)
$ vi readme1.txt

user.name@PC_NAME /d/tem/git_sandpit/play1/123 (test123)
$ cat readme1.txt
123
adding into test123 branch
change to go

user.name@PC_NAME /d/tem/git_sandpit/play1/123 (test123)
$ git checkout HEAD -- readme1.txt

user.name@PC_NAME /d/tem/git_sandpit/play1/123 (test123)
$ cat readme1.txt
123
adding into test123 branch

now you can see change to go is gone.


Example: reset to most recent submit HEAD
user.name@PC_NAME /d/tem/git_sandpit/play1/123 (test123)
$ cat readme1.txt
123
adding into test123 branch
changes to go staged
changes to go staged 2

user.name@PC_NAME /d/tem/git_sandpit/play1/123 (test123)
$ git checkout HEAD^ -- readme1.txt

user.name@PC_NAME /d/tem/git_sandpit/play1/123 (test123)
$ cat readme1.txt
123
adding into test123 branch

you can see below are gone.

changes to go staged
changes to go staged 2

For staged
1> git reset filename
2>git checkout reference filename , like git checkout HEAD filename


Example:
user.name@PC_NAME /d/tem/git_sandpit/play1/123 (test123)
$ vi readme1.txt

user.name@PC_NAME /d/tem/git_sandpit/play1/123 (test123)
$ git status
On branch test123
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   readme1.txt

no changes added to commit (use "git add" and/or "git commit -a")

user.name@PC_NAME /d/tem/git_sandpit/play1/123 (test123)
$ git add .

user.name@PC_NAME /d/tem/git_sandpit/play1/123 (test123)
$ git status
On branch test123
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   readme1.txt


user.name@PC_NAME /d/tem/git_sandpit/play1/123 (test123)
$ git reset readme1.txt
Unstaged changes after reset:
M       123/readme1.txt

user.name@PC_NAME /d/tem/git_sandpit/play1/123 (test123)
$ git status
On branch test123
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   readme1.txt

no changes added to commit (use "git add" and/or "git commit -a")

user.name@PC_NAME /d/tem/git_sandpit/play1/123 (test123)
$ git checkout HEAD -- readme1.txt

user.name@PC_NAME /d/tem/git_sandpit/play1/123 (test123)
$ git status
On branch test123
nothing to commit, working directory clean

user.name@PC_NAME /d/tem/git_sandpit/play1/123 (test123)
$ cat readme1.txt
123
adding into test123 branch

the extra line added via vi is gone !

Git stash pop - permission denied

I have just had this under Win 7.

$ git stash pop
error: cannot stat 'parentFolder/subfolder': Permission denied
error: cannot stat 'parentFolder/subfolder': Permission denied

Diagnosis:

1>I went to the subfolder and it's there and I couldn't delete it !

2>Use "process explorer" -> Find -> Find handles and Dlls -> put the "subfolder" name there and search.

Result: It turns out it's XMLSpy has opened one of the xml there, close XML Spy and try stash pop again, it's working now.

Thursday, 2 July 2015

Git - How to fetch only one remote created branch on Bitbucket under command line

Scenarios:
You have created a new bug fix/feature branch on Bitbucket (could be done via JIRA) call 'JIRATicket111-fix a bug' based on develop branch.

Let's say you want to get this branch and do your work, you can either do it from sourceTree by click on the [check out in SourceTree button]



But I don't want to checkout yet I just want to get the branch , you can do that from command line.

user.name@PC_NAME /d/work/GIT/projectv1-cucumber (JIRATicket111-module-compression-fix)
$ git remote -v
origin_h        https://NAME@bitbucket.org/mbv1/projectv1-cucumber.git (fetch)
origin_h        https://NAME@bitbucket.org/mbv1/projectv1-cucumber.git (push)

user.name@PC_NAME /d/work/GIT/projectv1-cucumber (develop)
$ git fetch origin_h JIRATicket111-module-compression-fix:JIRATicket111-module-compression-fix
Password for 'https://NAME@bitbucket.org':
From https://bitbucket.org/mbv1/projectv1-cucumber
 * [new branch]      JIRATicket111-module-compression-fix -> JIRATicket111-module-compression-fix

user.name@PC_NAME /d/work/GIT/projectv1-cucumber (develop)
$ git branch -v
  JIRATicket111-module-compression-fix 97fee45 @MBONE-184
* develop                       dcfe001 [behind 26]  System Log tests



Explain:
git fetch origin <remote_branch_name>:<local_branch_name>



Total visitors since Jan 2012

World Visitor Map