Sunday, June 7, 2015

Delete folder with same names in CMD Windows and too long file names.

I continued playing with Android Source Code in BitBucket.org. But a small condition makes my confused for a while. Since the Android Source Code is a huge project and thus contains a number of submodules which are storing in other Github or BitBucket repositories. So when I uploaded these submodules to repository, only hash value of them are transmitted to repository.


I believed Git should provided some ways to solve this issue, but I am still looking for it. But one simple solution is to delete all .git folder in those submodules, so that Github can not recognize them as submodules. A question comes, how to delete all folders with same name in CMD Windows system. This command could solve this issue:

for /d /r . %d in (.git) do @if exist "%d" rd /s/q "%d"

Change to the root directory of Android source code, and then run this command. But do not forget to initialize the local Github repository again. Because this command will also remove .git folder at the root directory.

During adding to local working repository, some files have too long names which caused fatal exceptions to Github. The beneath command will tackle this issue:

git config core.longpaths true

Then everything worked fine!

Uploading Android Source Code to BitBucket

I am recently playing around with Android Source Code for a challenging project, because I need to customize the Android System to match requirements. Later to introduce version control, I would like to upload the code to BitBucket. Since I am a new user for BitBucket, so some problems are worth being recorded.

First of all, down the Android 4.4.2 source code from my cloud storage: http://pan.baidu.com/s/1c06iLXY Sorry, I am Chinese so this interface is in Chinese as well. But I think Google Translate would help. The folder is really huge, almost 4 GB size. So to post this folder to your Github or BitBucket repository, it requires to change the default post buffer size. By default, the post buffer is 1MB. Let us assume to change the buffer to 5GB. You can use command:

git config http.postBuffer 5368709120

The granularity is in Bytes, you can change the setting in the config file of .git directory instead. Both ways would work. Then I encountered the following strange error in push, which trapped me for a while:

error: RPC failed; result=56, HTTP code = 0
fatal: The remote end hung up unexpectedly

After some searches, I found there are types to interacting with repositories in BigBucket: HTTP and SSH. So I change the connecting type from HTTP to SSH:

git remote set-url origin <ssh url of repository>

Then I pushed again, but one error occurs:

Permission denied (publickey)
fatal: Could not read from remote repository.

Ahha, I forgot to setup the ssh key in my computer, so type

ssh-keygen

and Enter button three times. Then copy the public key in ~/.ssh/id_rsa.pub to the Deployment keys panel of Settings of the repository. Everything should work fine, but later I got error again:

conq: repository does not exist.
fatal: Could not read from remote repository.

This is because I pasted the SSH key to the wrong place. I deleted the stored ssh key in Deployment Keys panel and go to Profile -> Manage account -> SECURITY -> SSH keys, and added the ssh key here. Then push again, everything works fine and the code has been successfully uploaded into the repository of BitBucket.org.