目录

git命令

# 查看远程分支情况
git remote show holla
# 远程分支已被删除,想同时把本地分支也清理了

远程 holla 仓库中已经没有的分支,通过这个命令把本地之前 fetch 下来的分支也修剪掉

可以通过 git remote show holla 查看到远程删除但是本地没删除的分支

git remote prune holla
# 查看已跟踪的仓库的远程分支和本地的分支
git branch -a
# 强制把a分支移动到跟b相同(把a与b对齐)
git branch -f <branch-a> <branch-b>
# 删除未在版本中的文件 (包括文件和文件夹)

建议先执行 git clean -nfd 查看一下要删除的文件

git clean -fd
# 从 git 仓库中删除一个文件,但工作空间还保留该文件
git rm --cached log.txt
# 从另一分支取出某一个文件到当前分支
git checkout feature-branch -- file1.txt
# 解除远程分支跟踪
git branch -d -r origin/master
# git merge --no-ff Fast-forward 和 Recursive 模式区别
  • 检出某版本的一个文件 git checkout a1e8fb5 hello.py
  • 还原回去 git checkout HEAD hello.py
  • 放弃本地修改,回到远程仓库的状态 git reset --hard <origin/master>

# Branch

  • 切换某一分支 git checkout a1e8fb5
  • 切换回来 git checkout master 或者 dev

#

  • 移动分支
  • 强制把a分支移动到跟b相同(把a与b对齐) git branch -f <branch-a> <branch-b>

#

  • 展示本地分支关联远程仓库的情况 git branch -vv
  • 关联远程分支 git branch -u <origin/mybranch>
  • 列出所有远程分支 git branch -r

#

  • 删除远程分支 git push origin :<remote-branch>
  • 删除本地分支 git branch -d <local-branch>
  • 强制删除本地分支(分支未合并到当前分支的情况) git branch -D <local-branch>
  • 远程删除了分支本地也想删除 git remote prune origin

#

  • 查看已合并到当前分支的分支 git branch --merged
  • 查看未合并到当前分支的分支 git branch --no-merged
  • 查看指定分支的合并状况 git branch --merged=<branch-name> / --no-merged=<branch-name>
[alias]
    co = checkout
    cob = checkout -b
    f = fetch -p
    c = commit
    p = push
    dc = diff --cached

    # Feature improving aliases
    st = status -sb
    a = add -p
    unstage = reset HEAD

    # Complex aliases
    plog = log --graph --pretty='format:%C(red)%d%C(reset) %C(yellow)%h%C(reset) %ar %C(green)%aN%C(reset) %s'
    tlog = log --stat --since='1 Day Ago' --graph --pretty=oneline --abbrev-commit --date=relative
    slog = log --pretty='format:%C(red)%h%C(reset)  %C(yellow)%ad %ar%C(reset) %d %n %C(yellow)%an%C(reset)  %C(green)%s%C(reset)    %n' --date=iso
    mlog = log --pretty='format:%C(red)%h%C(reset)  %C(yellow)%ad %ar%C(reset) %d %n %C(yellow)%an%C(reset)  %C(green)%s%C(reset)    %n' --date=iso --no-merges --author='Junnkang Zhang'
    lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
        #统计提交次数
    rank = shortlog -sn --no-merges
        #删除已完成合并的分支
    bdm = "!git branch --merged | grep -v '*' | xargs -n 1 git branch -d"

    # 比较两个版本差异文件 并导出zip压缩包
        # git export-zip <new_commit_id> <old_commit_id> <save_path>
        export-zip = "!f() { \
        git archive -o $3 $1 $(git diff --name-only $1 $2); \
      }; f"

##git merge

git merge 比较

  • git merge –no-ff 可以保存你之前的分支历史。能够更好的查看 merge历史,以及branch 状态。
  • git merge 则不会显示 feature,只保留单条分支记录。
  • git merge –squash:使用squash方式合并,把多次分支commit历史压缩为一次

git svn clone http://svn.creditease.corp/svn/FSO1.1/
--trunk=trunk/fso1.1/code/fso/h5.yixin.com
--authors-file=/Users/yixina-d/Desktop/users.txt
h5.yixin.com

上次更新: 2024/11/05, 03:15:29