2012年4月20日 星期五

[Git] Stashing


Here except some usage of stashing in git for memo.
All words is get from http://progit.org/book/zh/ch6-3.html

If you want to switch branches, but you don’t want to commit what you’ve been working on yet; so you’ll stash the changes. To push a new stash onto your stack, run git stash:
$ git stash
Saved working directory and index state \
  "WIP on master: 049d078 added the index file"
HEAD is now at 049d078 added the index file
(To restore them type "git stash apply")

At this point, you can easily switch branches and do work elsewhere; your changes are stored on your stack. To see which stashes you’ve stored, you can use git stash list:
$ git stash list
stash@{0}: WIP on master: 049d078 added the index file
stash@{1}: WIP on master: c264051... Revert "added file_size"
stash@{2}: WIP on master: 21d80a5... added number to log

In this case, two stashes were done previously, so you have access to three different stashed works. You can reapply the one you just stashed by using the command shown in the help output of the original stash command: git stash apply. If you want to apply one of the older stashes, you can specify it by naming it, like this: git stash apply stash@{2}. If you don’t specify a stash, Git assumes the most recent stash and tries to apply it:
$ git stash apply
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#
#      modified:   index.html
#      modified:   lib/simplegit.rb
#

You can see that Git re-modifies the files you uncommitted when you saved the stash. In this case, you had a clean working directory when you tried to apply the stash, and you tried to apply it on the same branch you saved it from; but having a clean working directory and applying it on the same branch aren’t necessary to successfully apply a stash. You can save a stash on one branch, switch to another branch later, and try to reapply the changes. You can also have modified and uncommitted files in your working directory when you apply a stash — Git gives you merge conflicts if anything no longer applies cleanly.
The changes to your files were reapplied, but the file you staged before wasn’t restaged. To do that, you must run the git stash apply command with a --index option to tell the command to try to reapply the staged changes. If you had run that instead, you’d have gotten back to your original position:
$ git stash apply --index
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#      modified:   index.html
#
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#
#      modified:   lib/simplegit.rb
#

The apply option only tries to apply the stashed work — you continue to have it on your stack. To remove it, you can run git stash drop with the name of the stash to remove:
$ git stash list
stash@{0}: WIP on master: 049d078 added the index file
stash@{1}: WIP on master: c264051... Revert "added file_size"
stash@{2}: WIP on master: 21d80a5... added number to log
$ git stash drop stash@{0}
Dropped stash@{0} (364e91f3f268f0900bc3ee613f9f733e82aaed43)

You can also run git stash pop to apply the stash and then immediately drop it from your stack.



2012年4月17日 星期二

ToolsMsmCA(Error):IHxFilters filter registration failure:Err = 0x80040305,Context = pFilters->SetNameSapce(Namespace)

I got an error message when I install WinCE 6.0 SDK.
ToolsMsmCA(Error):IHxFilters filter registration failure:Err = 0x80040305,Context = pFilters->SetNameSapce(Namespace)


Solution :
Adopt custom install and remove 'Documentation' from installing items.


Reference :

2012年4月16日 星期一

Error C2724 : 'static' should not be used on member functions defined at file scope

I do a stupid thing like below, so got message Error C2724 : 'static' should not be used on member functions defined at file scope

XXX.h
static void functionA();

XXX.cpp
static void functionA()
{
    // do something  
}

We have to remove the key word static from XXX.cpp, or the compiler will regard they are two different functions.
Further more, if you call the functionA(), you may also got the message, error LNK2019: unresolved external symbol 

[Git] cherry-pick



If you create a new branch which has five commits as fig. 1, and you'd like to merge D and F only into master as fig. 2.

A-B                             master
       \
        C-D-E-F-G         branch1
            <fig. 1>


A-B-D-F                     master
               \
                C-E-G         branch1
            <fig. 2>


All you have to do is....
$ git checkout master
$ git cherry-pick D
$ git cherry-pick F
$ git checkout branch1
$ git rebase master






Reference:
http://blog.luzi82.com/2010/08/git-cherry-pick-rebase.html

2012年4月12日 星期四

[Win API] Get Tick Count and Output Debug String

This is a sample to output string to debugger.


DWORD dwTickCount = GetTickCount();
LPWSTR szBuffer;
wsprintf(szBuffer, _T(" [Debug] The computer has ran %ld ms."),  dwTickCount);
OutputDebugString(szBuffer);



GetTickCount() :  Retrieves the number of milliseconds that have elapsed since the system was started, up to 49.7 days.
OutputDebugString() : Sends a string to the debugger for display.

2012年4月11日 星期三

[.Net] To Get Server Path


Server.MapPath is a static method which could get physical path from web server.
It is defined at namespace System.Web.HttpContext.Current.Server.MapPath
Example usages below:
1、Server.MapPath("/") : to get root path of web site.
       such as C:\Inetpub\wwwroot\
2、Server.MapPath("./") : to get path of the page, equal to Server.MapPath("")。
3、Server.MapPath("../") : to get parent path of the page.
4、 Server.MapPath("~/") : to get physical path of the application
       such as C:\Inetpub\wwwroot\ExampleSite\


Reference:

2012年4月6日 星期五

[Win API] Check directory or file exist


This is a example for check file or directory is exist or not before you access it.

    WIN32_FIND_DATA fileInfo;
    HANDLE hFind = FindFirstFile(unicodestr, &fileInfo);
    if (hFind == INVALID_HANDLE_VALUE)
    {
        bala...bala....
    }
    FindClose(hFind);


Reference:
http://blog.yam.com/csylvia/article/7026165