Thursday, January 14, 2016

Deleting git index file, a.k.a. more authoritative methods of dealing with Git line ending problems

The classic problem in Windows with line endings in files repeatedly rears its ugly head. I've tried a number of different ways over the years of dealing with them, but I discovered today that the gitattributes documentation actually gives a recipe for dealing with it, which I'll reproduce here:
$ echo "* text=auto" >>.gitattributes
$ rm .git/index     # Remove the index to force Git to
$ git reset         # re-scan the working directory
$ git status        # Show files that will be normalized
$ git add -u
$ git add .gitattributes
$ git commit -m "Introduce end-of-line normalization"
Source: http://git-scm.com/docs/gitattributes#_end_of_line_conversion

Meanwhile, the people over at Github have a slightly different approach. (I'm wondering if rm .git/index followed by git reset is the same as git rm --cached -r.) [EDIT: I realize upon studying this that this version will touch all files in the source tree, whereas the version above does not.]
$ echo "* text=auto" >>.gitattributes
$ git rm --cached -r .
$ git reset --hard
$ git add .
$ git commit -m "Normalize all the line endings"
Source: Refreshing a repository after changing line endings (Github)

The potential problem of the Github approach is that it would add files you might not want in your repository if your repository has any extra stuff in it, i.e. if doing a git status before their procedure shows any files not in the repository.

What's very interesting about the Github approach is that it's very similar to my method for removing all files from a repository that you'd actually like to ignore, except that my steps are missing the git reset --hard command:
$ git rm --cached -r .
$ git add .gitignore
$ git add .
$ git commit -m "Remove ignored files."


git reset vs git reset --hard

One thing I'm not sure of is the difference between git reset and git reset --hard in the Github approach. I'll have to think about that another time. :)

Saturday, January 09, 2016

Five advanced Git merge techniques

Some very interesting stuff here.

I knew about (but forgot) #1 -- including "base" in the merge file output -- but some of the other things are pretty interesting as well.

#4 -- git merge-file, which redoes the merge -- looks particularly interesting and powerful and helps out in the classic newlines style situations I often find myself in.

http://blog.ezyang.com/2010/01/advanced-git-merge/

This blog, subtitled "Existential Pontification and Generalized Abstract Digressions," and which I only recently discovered, seems primarily concerned with Haskell but has a huge helping of computer science articles as well. The name of the blog -- "Inside 736-131" -- sounds like the name of a computer science course at MIT. [Edit: now I see that it's apparently Stanford-specific.]

Tuesday, January 05, 2016

Keeping RDP sessions from locking due to inactivity

YMMV.

Create a VBS file with the following contents:
Do
 Set WSHShell = WScript.CreateObject("WScript.Shell")
 WSHShell.SendKeys ("{SCROLLLOCK}")
 Set WSHShell = Nothing
 WScript.Sleep (2*1000)
Loop 
Save as a VBS and run on whatever machine you want to stay open.


5/26/16 Edit: here's a better version that does not toggle the ScrollLock key and also increases the delay to minimize disruption:
Do
  Set WSHShell = WScript.CreateObject("WScript.Shell")
  WSHShell.SendKeys ("{SCROLLLOCK}{SCROLLLOCK}")
  Set WSHShell = Nothing
  WScript.Sleep (60*1000)
Loop

Monday, January 04, 2016

Git: removing cruft from a repository that was added without a .gitignore file

I inherited a Visual Studio project, originally in TFS, where the developer before me added files somewhat willy-nilly to the repository without any sort of filter. Thus, NuGet packages, the bin and obj directories, user settings, and even error logs were committed to version control.

Long story short, I scratched my head over how to clean up the repository such that ignored files were excluded from it. I started picking through by location, file type, and so on, but this took too long, was too tedious, and was likely to miss some files.

Finally, the solution hit me, and it's really quite simple. Here are the steps:

Step 1: remove the entire repository or folder.
$ git rm --cached -r .
Step 2 (optional): if it wasn't already present, add the .gitignore folder obtained from, e.g. the gitignore project:
$ git add .gitignore
Step 3: add back the folder
$ git add .
Step 4: commit the whole shebang:
$ git commit -m "Remove ignored files."
Voila! The resulting commit status (or diff) will show all undesired files being removed.


[5/26/16 Edit: here are all the lines of code together:
]