2

Git使用总结 2

 1 year ago
source link: https://iphyer.github.io/blog/2022/12/05/Git2/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

之前写过一个关于 Git 使用的总结 Git使用总结,但是现在看当时的总结真是挂一漏万,纸上谈兵。

这里总结下最近的一点 Git 使用心得,当然考虑到,对 Git 的理解还在不断使用中提高,这里也只是挑重点总结。

git commit –amend –no-edit

git commit –amend –no-edit 也是特别常用的,主要的目的是在提交代码之后如果需要修改,但是不想留下新的 Commit 记录。 有时候我们希望 Commit History Clean,所以我们会提交修改但是不增加新的 Commit 记录。

git reset –hard origin/master

这个也是特别需要注意的代码,当然主要是你确定你的本地修改没有必要保留再使用。 这里会强行把你本地的代码同步到远端仓库的代码状态。

Then that just resets my (local) copy of master (which I assume is screwed up) to the correct point, as represented by (remote) origin/master.

WARNING: You will lose all changes not yet pushed to origin/master.

一半来说如果你特别小心的每次修改前都 sync 代码,不会出现这个的使用场景,但是在复杂代码的开发过程中确实是会出现这个情况。

Git Revert

Git Revert 和上面的 reset 类似,都是小心使用不会需要的命令,但是如果需要的时候也是需要学会怎么使用的。

参考这个帖子 master branch and ‘origin/master’ have diverged, how to ‘undiverge’ branches’?

git revert –no-commit 5bcdd83a26e5a365bda30198f64db167cdd934d7^..HEAD

当然要注意这个命令比较危险,是需要特别注意的。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK