且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我在使用Git开发时的一些命令分享

更新时间:2022-06-27 07:45:02

我在使用Git开发时的一些命令分享

以下是我认为比较实用的在开发过程中经常会用到的Git命令集合:如果大家有比较好的,也可以分享出来。

查看git历史commit记录的图形

git log --oneline --decorate --graph

删除本地branch

git branch -D branchname

删除远程branch

git push origin --delete branchtodeletedname

删除上一次commit

delete last commit:

git reset --soft HEAD~1

撤销“删除上一次的commit”的操作

revert delete last commit:

git revert HEAD

重做所有的改变为原始的状态

undo changes:

Revert changes to modified files.

git reset --hard

Remove all untracked files and directories. (-f is force, -d is remove directories)

git clean -fd

删除最近的第二个commit

delete the second commit:

git rebase --onto GetHostUT~2 GetHostUT~ GetHostUT

删除最近的第二个和第三个commit

delete the second and third commit:

git rebase --onto GetHostUT~3 GetHostUT~ GetHostUT

同步master branch让它和服务器上一致

sync server to local for master branch:

git checkout master
git fetch
git pull origin master
git reset --hard origin/master

同步当前的branch历史为最新master,而又保留当前branch已提交的commit

sync master to current branch:

git checkout master
git pull origin master
git checkout GetHostUT
git rebase master
git push origin GetHostUT -f