Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
962 views
in Technique[技术] by (71.8m points)

git怎么强制同步一个分支代码到本地呢?

首先,我在master分支下修改了a.txt文件,commit提交,然后push到dev分支,然后我checkout切换到master分支,我想要的效果是此时本地应该自动同步去除a.txt文件,因为我并没有将a.txt提交到master分支,但是无论我怎么切换,a.txt文件始终存在本地上,怎么样才能强制切换成全是master分支的代码呢?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

那你 commit 应该就在 切换到 dev 分支后进行呐。
现在这样的话。

# 切换至 master
git checkout master
# 重置当前 HEAD 到远程 HEAD
git reset --hard origin/master
# 拉取远程分支
git pull

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...