问题
I am little bit new to Git.I would like to push some files to my git origin(remote).
What I did: I had my master -> I created a branch to do some job -> after that I merged my branch to my master.During my work a lot of binary files and project files were changed/added locally. I would like only to add .java files which changed to remote server. (I believe that I experimented with commits when i worked on my branch. just to check how it work)
My master is is up to date with my origin(that what get when I do git pull
also I did git fetch origin
.
I always receive:(when I ran git status
)
On branch master Your branch is ahead of origin/master by 12 commits.
(use "git push" to publish your local commits)
nothing to commit, working directory clean`
I tried to add, commit those files but running git status
wasn't changed.
I tried to to do add, commit on New branch
On branch NewBranch nothing to commit, working directory clean
I tried to reset Head. I didn't find solution for my problem in git tutorial or in Stack.
Of course I can push all files to remote origin but I don't think its a good solution. some duplicate question that I found: How to push a single file,how to push changes made to only certain files?, How to commit only some files?
Thanks A Lot.
回答1:
- Create a new branch from master
git checkout master
git checkout -b new_branch
- Checkout just the file you want from your old branch
git checkout old_branch path/to/some/file
- repeat as necessary for additional files
- Commit the files to your new branch
git commit -a
- Push new branch to your origin
git push origin master
回答2:
I solved my problem: (I was confused with git status response because it wasn't changed when I tried to add/commit files which were already there).Thanks to linuxdan and DaveZych and Temich.
git checkout -b NewBranch
After that I deleted all unnecessary files.
git rm --cache build/web/WEB-INF/classes/doggizz/utils/\*.class
Move back to master
git checkout master
(only disadvantage that those files were deleted when I moved back to master so I copied manually project file , I tried to stash before checkout but it didn't helped)
git merge NewBranch
git push
来源:https://stackoverflow.com/questions/25689214/how-to-push-certain-files-to-origin-master-in-git