## Git basic - settings * git config --global core.editor vim * git config --global user.name nixawk * git config --global user.email nixawk@demo.com * git config --global color.diff auto * git config --global color.status auto * git config --global color.branch auto #### 在工作目录中初始化新仓库 * git init * git add README.md * git commit -m 'new project' #### 从现有仓库克隆 * git clone git://github.com/someone/project.git * git clone git://github.com/someone/project.git myproject #### 检查当前文件状态 * git status #### 跟踪新文件 * git add README.md #### 忽略某些文件 * cat .gitignore ``` # 此为注释 – 将被 Git 忽略 # 忽略所有 .a 结尾的文件 *.a # 但 lib.a 除外 !lib.a # 仅仅忽略项目根目录下的 TODO 文件,不包括 subdir/TODO /TODO # 忽略 build/ 目录下的所有文件 build/ # 会忽略 doc/notes.txt 但不包括 doc/server/arch.txt doc/*.txt # ignore all .txt files in the doc/ directory doc/**/*.txt ``` #### 查看已暂存和未暂存的更新 * git diff * git diff --cached #### 提交更新 * git commit #### 移除文件 * git rm README.md * git rm -f README.md #### 移动文件 * git mv README.md README.txt #### 查看提交历史 * git log * git log -p -2 * git log --pretty=format:"%h - %an, %ar : %s" #### 修改最后一次提交 * git commit -m 'commit message' * git add README.md * git commit --amend #### 取消已经暂存的文件 * get reset HEAD README.md #### 取消对文件的修改 * git checkout -- README.md #### 查看当前的远程库 * git remote -v #### 添加远程仓库 * git remote add dev git://github.com/someone/project.git #### 从远程仓库抓取数据 * git fetch dev #### 推送数据到远程仓库 * git push [remote-name] [branch-name] * git push origin master #### 查看远程仓库信息 * git remote show origin #### 远程仓库的删除和重命名 * git remote rename dev development #### 列显已有的标签 * git tag * git tag -l 'v1.4.2' #### 查看分支 * git branch * git branch -v * git branch --merged * git branch --no-merged #### 添加分支 * git branch dev * git checkout -b dev #### 切换分支 * git checkout dev #### 合并分支 * git checkout master * git merge dev #### 删除分支 * git branch -d dev * git branch -D dev #### 推送本地分支 * git push origin dev #### 跟踪远程分支 * git checkout --track origin/dev #### 删除远程分支 * git push origin :dev #### 记录回滚 git reset --hard old-commit-id git push -f origin branch #### GITHUB SSH KEY ssh-keygen -t rsa -b 4096 -C "your_email@example.com" eval "$(ssh-agent -s)" ssh-add ~/.ssh/yourPrivKey git remote set-url origin git@github.com:<Username>/<Project>.git > create a new git repository ``` git config --global user.name "someone" git config --global user.email "someone@demo.com" mkdir project cd project git init touch README.md git add README.md git commit -m "first commit" git remote add origin git@github.com:someone/project.git git push -u origin master ``` > http://www.git-scm.com/book/ https://help.github.com/articles/generating-ssh-keys/ http://stackoverflow.com/questions/14762034/push-to-github-without-password-using-ssh-key |
Linux - git notes
最新推荐文章于 2024-04-05 09:38:29 发布