4

Git 舍弃本地修改并使用远程代码覆盖本地代码

 2 years ago
source link: http://i.lckiss.com/?p=7527
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.

Git 舍弃本地修改并使用远程代码覆盖本地代码

2021-10-02

有时候自己改了好几个提交,但是发现不需要了,想直接切回线上的新代码,就像强制覆盖远端代码一样,我以为是加上–force,后来发现还是太年轻。

方法有很多,比如:

1、删分支再重新拉取,不过会留下一些没被跟踪的文件。

2、将当前分支的提交 reset –hard 到与线上某次提交相同的位置,再 pull,这个可以做,但到哪儿还得看看。

所以用这种方式比较稳妥:

git fetch --all
git reset --hard origin/branch_name
git pull

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK