git常用命令(持續更新)

1、回退工作區中文件部分代碼
git checkout -p

2、stash部分代碼
git stash -p
git reset --hard
git stash pop
或者:
git stash -p
git stash drop

3、查看最近的結點操作,即使已經被reset掉
git reflog
配合git reset --hard xxxx可進行reset的恢復

4、撤銷本地的commit,保持和遠程結點一致
git reset --hard origin/my-branch

5、結點回退
git reset --hard HEAD^ 或 git reset --hard a135d8e

6、cherry pick branck1的到branck2
git checkout branch2
git cherry-pick e3851e8

7、rename 一個分支
git branch -m new-name
git branch -m old-name new-name

8、查看我剛剛的提交
git show
git log -n1 -p

9、刪除最近一次commit
git reste HEAD^ --hard
git push --force-with-lease [remote] [branch]
沒有push的話
git reset --soft HEAD@{1}

10、add 文件裏部分代碼的修改
git add -p filename.x
如果是新文件
git add -N filename.x

11、把branch1中unstaged的修改移到branch2
git stash
git checkout branch2
git stash pop

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章