Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pushing without committing

Tags:

git

I have a git repo and I just pushed it to a server. Then I setup a post-receive hook on the server. I want to check it works. I have to commit again just to see if it works? I would really like to just force a push while I'm trying to get this set up rather than keep making commits that have no real value. Its not working, and I just don't get it.

$ git push --force origin master
Everything up-to-date
like image 715
ThomasReggi Avatar asked Jun 26 '12 21:06

ThomasReggi


2 Answers

You need to push an older commit to achieve this. For example, you could push the commit right before the current HEAD using this comment:

git push --force origin HEAD^:master 

After this you can push the HEAD commit again:

git push origin master

However, instead of pushing all the time consider calling the hook manually. That's usually easier - but don't forget to test with an actual push when you think everything works just to be sure.

like image 195
ThiefMaster Avatar answered Oct 31 '22 22:10

ThiefMaster


There's a little dirty trick you can use:

git stash save && git push --force origin "stash@{0}:master" && git stash pop

This does 3 things:

  1. Stash current uncommitted changes. Stashing creates a new commit, but on a separate ref. It will not dirty your history. Additionally, it clears the working directory from the changes. See step 3.
  2. Push the stashed code
  3. Pop the stash - clearing the stash and placing all the files back in your working directory.

This will effectively push all files to the remote without creating a local commit.

like image 29
tmr232 Avatar answered Oct 31 '22 20:10

tmr232