2013-11-07

git 常用操作

Views: 17533 | 1 Comment

创建分支

git branch abc

切换分支

# 本地
git checkout abc
# 远端
git fetch
git checkout abc
或者
git branch abc origin/abc

删除分支(本地)

git branch -d abc

删除服务器上的分支(远端)

#git push origin :abc
#或
#git push origin --delete abc
然后, 其它人必须调用 git fetch -p 同步状态

合并分支到主干

git checkout master
git pull
git merge --no-ff abc

对比分支

git diff master abc

列出远程分支

git branch -a

修改 commit log

git commit --amend

查看文件变动历史

git log --name-status

git 回滚

# 查看历史
git log
git reset --hard comit_id
git push -f origin branch_name

如果遇到类似 "The requested URL returned error: 401 Unauthorized while accessing" 的错误提示.

Instead of:
git clone https://github.com/org/project.git
do:
git clone https://username@github.com/org/project.git
or
git clone https://username:password@github.com/org/project.git

git diff 忽略掉新文件

--diff-filter=M

分支覆盖

用 dev 分支覆盖 master 分支(删除 master, 然后重建).

git checkout dev
git merge --strategy=ours master    # keep the content of this branch, but record a merge
git checkout master
git merge dev             # fast-forward master up to the merge

git tag

git tag abc
git push origin abc

git tag -d abc
git push origin :refs/tags/abc

git log

git log
git log -p file

git diff

git diff origin/master
git diff commit_1 commit_2 file

清除密码保存

# 明文保存密码
git config credential.helper store
# macOS 保存密码
git config credential.helper osxkeychain

Related posts:

  1. 不用 git rebase 合并 commit 历史
  2. 解决从github匿名获取只读repo错误
  3. SSDB 采用里程碑式版本发布机制
  4. CVS笔记
  5. 为什么iComet比nginx-push-stream-module更好?
Posted by ideawu at 2013-11-07 13:39:48 Tags:

One Response to "git 常用操作"

Leave a Comment