简体   繁体   中英

Pushing just one revision to GIT repository

i am working in a project and as i make one change i commit it. Then, after commiting 3 or 4 changes i push it all.

What i would like to do is to push just one of those revisions that i have locally. can i do that? How?

Thanks

Try working in a local 'work' branch. This has advantages such as you can switch to a different branch if you get called to work on say, a bug.

When you're ready to push: git checkout master, git pull, git merge work, git push, will be your normal flow.

However, you can cherry-pick commits from your work branch to the master, that way only those commits will be pushed.

git checkout master
git cherry-pick <id of commit you want>
git push

You could likely do this even now.

git checkout -b work
git log (and look for the IDs of the commits you want)
git checkout master
git reset --hard HEAD~3 (remove last 3 commits from master)
git cherry-pick <ID of commit you want>
git push

I'm not quite sure what you want to do. If you have 4 unpushed commits and you only want to push the first of those commits, you could pass its ref to git push . If you want to push, say, the third of those commits, but not the first or the second, you will have problems. You can't really do that. (Well OK, you probably can, but then it would be disconnected from the rest of the tree).

If you simply want to collapse your four commits into a single commit before pushing, you might want to work in a separate branch and use squash merges. You can't push a commit to the remote repository until it exists in your local repo. You can't synthesize a commit as part of the push (as far as I know).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM