git 基本命令

TzhfI0.png

git - remote

git remote add origin git@github.com:Encyclopedias/MavenRepo.git

git — stash

display all stash list: git stash list

delete all stash list: git stash clear

delete one of stash: git stash drop stash@{number}

use one of stash: git stash apply “stash@{number}”

git — push

push the local branch to remote branch[first]: git push origin localBranch:remoteBranch

push to remote branch: git push origin remoteBranch

git — pull

get remote branch data: git pull origin branchName

git — reset

reback the file that is added to temporary cache by mistake: git reset file

git restore –staged {filepath}

git — branch

get the remote branch list : git branch -a

delete remote branch:**git push origin –delete **

delete local branch: **git branch -d **

remove the relation of local branch and remote branch: git branch –unset-upstream

update branch name in local: git branch -m oldName newName update branch name in remote: git branch -m oldName newName

update remote branch git remote update origin –prune

git — reflog

check the branch origin: git reflow show {branchName}

git — cherry pick

get the all changes of the commit: **git cherry-pick **

get the change from commit A to commit B: get cherry-pick A..B

Repack the old status and exit the cherry pick: git cherry-pick –abort

git — commit

update the commit message: git commit –amend

commit the code: git commit -m “note message”

if you add the useless file to local repository, you can remove the file: **git restore –staged ...**

git— checkout

list all branch: git branch

create and change the branch: git checkout -b {branchName}

change branch: git checkout/switch {branchName}

create a new branch based on remote branch: git checkout -b {newBranchName} origin/release

git — delete

delete the branch : git branch -d {branchName}

delete the branch force: git branch -D {branchName}

delete remote branch: git push origin –delete {branchName}

git — config

get the name or email of commit: git config user.name git config user.email

update the name or email: git config –global user.name “your name”/ git config –global user.email “your email”

git config –globalunset ‘user.name’ git config –globalunset ‘user.email’

git - revert

git版本回退 1.已经commit但还没有push

git reset --soft + 提交记录版本号 撤销commit

git reset --mixed + 提交版本号 撤销commit和add 两个操作

  • 先使用git log查看提交记录 获取最近一次提交的上一次的提交版本号
  • 使用git reset - -soft 粘贴一中的版本号

2.已经commit并且已经push了

git reset --hard + 提交版本记录 回退到该提交版本的位置 并且该版本后的提交记录不在显示

比如说想回到5eb7444126ef10f3bcd1a9daca7b81051d9533df这个状态,也就是撤回最后一次提交,记下这个对应的SHA-256值,然后按q键退出vim。 然后,使用git reset来重定向HEAD指针:
如果你要连着本地文件一块儿撤回(也就是删除本地文件):
$ git reset --hard 5eb7444126ef10f3bcd1a9daca7b81051d9533df 如果你只要撤回远程(本地文件不动):
$ git reset --soft 5eb7444126ef10f3bcd1a9daca7b81051d9533df

git reflog 查看hard重置后的log

git revert + 需要移除的版本记录(可以使用空格 加上多个版本号)返回到移除版本记录的上一一个记录 并且为这次回退重新生成一次commit

上述是对于一次提交的整体回退,如果只想回退该提交中的某个文件:
  1. git log + 该命令行下的路径文件
  2. git checkout commitId 该命令行下的路径文件 //此时文件已经回退 但是你得提交回退的改动
  3. git commit -m “message”
  4. git push origin localBranch:remoteBranch