pydata: Huiming's learning notes

Keep Looking, Don't Settle

fix git error for blog

为了自动给blog备份,我把blog放在dropbox里面,这样主机和vmware上的ubuntu_dl机器可以同步,而且dropbox在线还有一份,这样不同意丢了。即使不小心删掉也会有online的备份。

可是一个问题是老是会出现git的error,比如

hhh@ubuntu:~/Dropbox/blog/output$ git commit -m "test"
error: object file .git/objects/d2/f4c036db03671b6d859b137e4ccdc06383fb14 is empty
error: object file .git/objects/d2/f4c036db03671b6d859b137e4ccdc06383fb14 is empty
fatal: loose object d2f4c036db03671b6d859b137e4ccdc06383fb14 (stored in .git/objects/d2/f4c036db03671b6d859b137e4ccdc06383fb14) is corrupt

hhh@ubuntu:~/Dropbox/blog/output$ git commit -m "test"
fatal: could not parse HEAD

好像是.git下面的文件因为dropbox同步什么的出现了问题。解决的办法也很简单。

  1. blog/output文件夹, cd output, 删掉里面的.git文件夹 rm -rf .git
  2. clone github的文件 git clone git@github.com:songhuiming/songhuiming.github.io.git
  3. 这个时候在output文件夹下面会出现文件夹songhuiming.github.io
  4. songhuiming.github.io里面的.git文件夹复制到output下面, cp -rf songhuiming.github.io/.git .
  5. 删掉文件夹songhuiming.github.io
  6. 重新到blog文件夹下面make html然后就可以正常git commitgit push

pip install -e . to install a package

mypackage folder has the following tree structure:

.
├── Config
├── __init__.py
├── README.md
├── setup.py
├── .gitignore
└── src
    ├── basecode
    │   ├── aws
    │   │   └── aws.py
    │   ├── dataprocess
    │   │   └── dataprocess.py
    │   └── utils_old
    │       ├── old.py
    │       ├── temp.py
    │       └── utils.py
    └── mypackage.egg-info
        ├── dependency_links.txt
        └── top_level.txt

setup.py

from setuptools import setup, find_packages

 setup(
     name='mypackage',
     version='0.1',
     packages=find_packages(where="src", exclude=("test",)),
     package_dir={"": "src"},
     entry_points={
         'console_scripts': [
             'pwd=basecode.sys.sysos:print',
         ],
     },
 )

.gitignore

 .gitignore
 src/basecode/utils_old
 mypackage.egg-info

git

四个区域: 硬盘 /(git add →) 暂存区 / (git commit → ) local / (git push →) remote

  1. git clone xxx
  2. git checkout -b mybranch # create my own branch
  3. code change, bala bala
  4. git diff # check what I changed
  5. git add . # add code to stage 暂存区
  6. `git commit -m "xx"`` # commit to local.
  7. git push origin mybranch # push to remove mybranch
  8. 但是在push的时候,可能remote的master已经有人更改代码了。这个时候要把remote最新的变化跟我的代码变化merge起来
  9. git checkout master # 切换到master branch
  10. git pull origin master # pull remote的代码到 local 和 本地硬盘
  11. git rebase master # 把我的修改放一边,把remote的代码拿过来,然后再尝试把我的修改的代码弄进去到master(注意,不是merge,尽管最后结果是把两个code merge成最终版本)。这个时候可能有rebase conflict,需要手动解决; reapply the commits from your current branch on top of the master branch. It effectively changes the base of your branch to the latest commit in master.
  12. git push -f origin mybranch # 需要 -f 来强制push
  13. pull request, remote code owner will do squash and merge
  14. git remote -v # check remote
  15. git remote add share $(git config remote.origin.url)/share/shmtest # create remote share/shmtest
  16. git push share shmtest # push to the remote share
  17. git push share HEAD # if I don't have permission so I cannot push my changes there; another to push current branch (shmtest) to remote share