git 命令指南

2022-05-05  本文已影响0人  _若无

整理一下 git 命令,用时总会忘记。

Git常用命令

git clone -b 分支名称  远程地址
git config user.name
git config user.email
git config --global user.ame "foo"
git config --global user.email "foo@email.com"
git config user.name "foo"
git config user.email "foo@mail@com"
git config --global --list
git config --local --list
git config --local user.name
git branch (查看当前分支)
git branch -a (查看所有分支)
git branch 分支名 (创建分支)
git branch -d  分支名(删除分支)
git branch D 分支名 (强制删除未合并的分支)
git checkout 分支名 (切换到对应分支)会自动将代码更新为分支代码
git checkout -b 分支名 (`基于分支名或commit值` 切换分支并直接切换过去)
history
history | grep push
git log
git log --summary  (--summary 查看已经提交的文件详细变化)
git log dev..master
git reset HEAD foo.js
git checkout -- foo.js
git diff
git diff HEAD
git diff --staged
// 重新添加
git add "*.html"
// 重新提交
git commit --amend
git add "*.js"
git reset  文件路径
git rm "*.html"
git merge 分支名
git merge --abort
git checkout -- <文件路径>
git stash
git stash save "命名"
// 将当前stash中的内容弹出,并应用到当前分支对应的工作目录上 `注:该命令将堆栈中最近保存的内容删除(栈是先进后出)`
git stash pop 
// 释放指定代码
git stash pop stash@{0}
git stash list
//  `stash@{0} 为栈中名称`
git stash drop stash@{0}
git stash clear
git fsck --unreachable |
grep commit | cut -d\  -f3 |
xargs git log --merges --no-walk --grep=WIP
// 找到对应的 commit hash值
git stash apply hash值
git push origin --delete branchname
git log // 找到对应 commit hash 值
git reset --hard hash值
git revert Head/[commit hash]
git remote set-url origin git@foo.bar.com:a/hello.git
git push --set-upstream origin preproduction
git push origin <tag_name>
git push --tags
git tag --list
// --cached 仅删除index, -r(recursive) 递归删除.idea目录下的所有文件
git rm --cached -r .idea
git add <file(s)>/.
git reset HEAD <file(s)>/.
git reset HEAD <file(s)>/. && git checkout -- <files>/.
git add -u
git reset --hard
git diff HEAD [commit has fragment]
git rebase -i HEAD~2/hash
pick && squash
:wq!
git remote -v
git rebase --abort
reset soft
...reset
git push --force
git reflog  // 找出最新的commit sha1值HEAD@{1}比HEAD@{2}新
git branch branchName <sha1>
git fetch 更新 origin/*下所有的分支,在发布git flow feature 前很有用,用于更新remote分支
git pull 主要用来更新多人合作的当前分支,多用于更新local分支
git fetch --prune
`-prune:  Before fetching, remove any remote-tracking references that no longer exist on the remote.`
git remote show origin

-假如远程已经不存在分支,git fetch --prune也更新不到状态,该如何做?

git push origin --delete feature/fix-chat-unread-msg-async
git remote prune <name>
git rm -r --cached 文件名
          add                   commit
工作目录 ------------> 暂存区  ------------> 版本历史
暂存区:git已经获得了对文件的管理权限,暂存区文件有状态:new file,deleted,modified等等。
版本历史:git log查看每一次commit记录。
上一篇 下一篇

猜你喜欢

热点阅读