git 常用命令

1、git config --system --unset credential.helper // 账号密码变动重置

2、git 解决每次更新代码都要输入用户名密码的解决方案

  git config --system --unset credential.helper

  git pull /git push (第一次输入,后续就不用再次数据)

ssh-keygen -t rsa -C ”yourEmail@example.com” // 生成ssh

rd /s /p node_modules // windows强制删除

git add * -f // 添加所有文件

git add .    //添加更新文件

git add /src -u // 添加已追踪并且修改的的文件,/src 代表某个路径下的,可不写

git commit -m '本次提交的描述' // 提交文件

git pull origin [branch name] // 拉去地址分支的最新代码

git push origin [branch name] // 提交到远程

git branch // 查看分支和当前分支

git checkout [branch name] // 切换分支

git checkout [branch name] -b // 创建并切换到这个分支

git merge [branch name] 合并分支

git clone git@****.com // 克隆远程仓库

git remote add origin **** // 添加远程仓库

git log  // 查看提交记录

git log --pretty=oneline // 一行展示提交记录

git log --online --graph // 显示合并记录图

git reflog // 查看仓库的操作历史

git show  <tagname> // 查看标签的详细信息

git rm -r -f --cached ****/ // 删除远程的目录(删除后需重新提交更新仓库)

例: 如果已经提交node_modules到仓库

  .gitignore文件上写上:
    node_modules/

  进入仓库目录,删除github仓库上.gitignore上新加的选项
    git rm -r --cached node_modules/

  重新添加要提交的选项
    git add .
    git commit -m 'remove node_modules'

  最后在git push 到远程仓库上就可以了。
    git push

git push --set-upstream origin 分支名 // 推送本地分支到远程仓库

git fetch // 拉取远程的所有分支

git tag -a v1.1 -m '打tag' // 打tag

git push origin v1.1/--tags // 推送tag

git tag -d v1.1 // 删除本地tag

git push <remote> :refs/tags/<tagname> // 更新远程

git push origin --delete <tagname> // 删除远程tag

git checkout -b 本地分支名 origin/远程分支名 // 将远程git仓库里的指定分支拉取到本地(本地不存在的分支)

// 删除分支

我现在在develop分支上,想删除develop分支

  1 先切换到别的分支: git checkout master

  2 删除本地分支: git branch -d develop

  3 如果删除不了可以强制删除,git branch -D develop

  4 有必要的情况下,删除远程分支:git push origin --delete develop

  5 在从公用的仓库fetch代码:git fetch origin develop:develop

  6 然后切换分支即可:git checkout develop

 更改本地和远程的分支名称
git branch -m old_branch new_branch # Rename branch locally 
git push origin :old_branch # Delete the old branch 
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
  1. 删除本地的bug_xzx分支;git branch -D bug_xzx

  2. 删除远程的bug_xzx分支;git push origin --delete bug_xzx

  3. git放弃本地修改

    一、未使用 git add 缓存代码时。

    可以使用 git checkout -- filepathname (比如: git checkout -- readme.md  ,不要忘记中间的 “--” ,不写就成了检出分支了!!)。放弃所有的文件修改可以使用 git checkout .  命令。

    此命令用来放弃掉所有还没有加入到缓存区(就是 git add 命令)的修改:内容修改与整个文件删除。但是此命令不会删除掉刚新建的文件。因为刚新建的文件还没已有加入到 git 的管理系统中。所以对于git是未知的。自己手动删除就好了。

    二、已经使用了  git add 缓存了代码。

    可以使用  git reset HEAD filepathname (比如: git reset HEAD readme.md)来放弃指定文件的缓存,放弃所以的缓存可以使用 git reset HEAD . 命令。

    此命令用来清除 git  对于文件修改的缓存。相当于撤销 git add 命令所在的工作。在使用本命令后,本地的修改并不会消失,而是回到了如(一)所示的状态。继续用(一)中的操作,就可以放弃本地的修改。

    三、已经用 git commit  提交了代码。

    可以使用 git reset --hard HEAD^ 来回退到上一次commit的状态。此命令可以用来回退到任意版本:git reset --hard  commitid 

     

未完,待续...

原文地址:https://www.cnblogs.com/detanx/p/gitOptions.html