How to push certain files to origin/master in git?

99封情书 提交于 2019-12-10 12:49:53

问题


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:


  1. Create a new branch from master
    1. git checkout master
    2. git checkout -b new_branch
  2. Checkout just the file you want from your old branch
    1. git checkout old_branch path/to/some/file
    2. repeat as necessary for additional files
  3. Commit the files to your new branch
    1. git commit -a
  4. Push new branch to your origin
    1. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!