git

Git实践

  • Git 有三种状态

    • 已提交(committed)
    • 已修改(modified)
    • 已暂存(staged)
  • Git global setup:

    1
    2
    git config --global user.name "username"
    git config --global user.email "username@baidu.cn"
  • Create Repository

    1
    2
    3
    4
    git init
    git config user.name "username"
    git config credential.helper wincred //Caching password in git
    git remote add origin https://git.corp.qihoo.net/kidsguard-web/elder.git
  • delete remote branch

    1
    git push origin --delete branchName
  • GIT关键字

    • pull 拉取远程的repo 仓库内容
    • fetch
    • push 将修改推送到远程的仓库
    • checkout 切换分支
    • branch test 创建test 分支
    • rebase 修改master指针的位置,使得本branch上面的提交都在最新master之后保持提交树的线性关系。
    • add 这个命令理解为“添加内容到下一次提交中”而不是“将一个文件添加到项目中”要更加合适。
    • reset SHA 会保留工作目录(working directory)。这些提交虽然消失了,但是内容还在磁盘上
    • reset –hard SHA “撤销”所有提交和本地修改 (-hard不保留本地磁盘数据)

pull & push (push 类似)

1
2
3
git pull <远程主机名><远程分支名>:<本地分支名>
git pull origin next:master //origin主机的next分支,与本地的master分支合并。
git pull origin next //远程分支是与当前分支合并

reset

1
2
3
4
git reset -soft head~ 回滚到前一次提交之前
git reset --hard HEAD~~ 回滚到前一次提交
git reset --hard <commit ID号>
git push -f 回滚远程提交的

checkout

1
2
3
git checkout -b newtest 本地新建一个名为newtest的分支
git checkout -b localtest origin/test 创建branch为localtest,repo为origin/test.
git branch -u origin/my_branch change upstream 的分支

装作特别有钱