Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

git push - git force local file on top of origin

I'm helping my coworkers transition from SVN to Git.

One of their workflow was to simply force push a single file on top of the svn repo. Their working directory might have some unchecked diffs, they might have a few local commits, but they need a convenient way to push just a specific file on top of the repo.

I'm not familiar with svn but I understand the expected behavior would be to apply the local diff on top of origin, and resolve any issues, or maybe silently override the remote when the diffs can't be merged.

I appreciate wanting to push a single file like this is not really the philosophy of git. However their use case seemed basic enough that I'm a bit disappointed I haven't found a good recommendation yet.

I guess the ideal behavior would be to get the local commits to the file (so including that file only changes for commits that had this file + others, keeping the same commit message) and force push this to the central repo. I'm not sure how to do that exactly, but at least generating a patch of the working directory changes + local only commits is possible with git diff origin/master -- file ; and I'm hoping I can find a git am kind of way to force this on the central repo...

I think they're hoping to not have to touch their working directory to get this done, so stashing / switching branches would be considered inconvenient; they work locally without committing and only sync up say once a month.

Any thoughts would be much appreciated.

question from:https://stackoverflow.com/questions/65545711/git-force-local-file-on-top-of-origin

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

1 Answer

0 votes
by (71.8m points)

I think they're hoping to not have to touch their working directory to get this done,

Then they should simply modify that file using the online editor of the remote Git hosting service they are using (at work, I use an on-premise Gitea service, for instance)

That will create one commit, with just that file modification in it.
And it won't necessitate any local modification/branch switching.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...