TheTrueTDF
TheTrueTDF

Reputation: 184

Patch deployment - git doesn't fetch the latest remote commit

I need to apply a patch but:

  1. The patch (.sh script to run) breaks the website (a little).
  2. I fixed the pages broke by the patch and committed the modifications in git.
  3. The patch modify both the file system and database.
  4. The patch cannot be applied if it detects that some of its content is already applied, which mean I cannot do a git pull and then execute the script for my patch. I must apply the patch and then apply my fixes to that patch.
  5. I cannot do a git pull once the patch is applied (Your local changes to the following files would be overwritten by merge)

Usually I would :

  1. Apply the patch
  2. Do a git -fetch
  3. Do a git reset --hard

The problem is the git -fetch has no effect:

git log | head

and

git log origin | head

have the same output, though the origin repository is 4 commits ahead (and git knows that when I do a git status).

What I'm trying to do (TL;DR):

I would like to fetch my last commits from the remote repository so that I can do a hard reset after.

Upvotes: 1

Views: 134

Answers (2)

TheTrueTDF
TheTrueTDF

Reputation: 184

My mistakes were actually quite simple. The right command to display the log was:

git log origin/branchname

I was then confirmed that the git fetch worked fine.

Then I did:

git reset origin/branchname --hard 

It worked a lot better. A simple git reset would just set the code to the last local commit, when I wanted the last remote one.

Upvotes: 1

peterh
peterh

Reputation: 1

I suggest to give more data, and show clear commands and error messages. To your question people can give you only a conceptional answer, which may or may not be enough for you.

What should surely work:

  1. You can get back to the pre-merge state of your code, with git reset.
  2. You can retry the merging with git pull.
  3. Which is very important: you should get your system into a state, where everything mergeable is already merged, even if it doesn't work! So, do the merge and solve the merge conflicts. All of them.
  4. Watch to save every changes: git add ., git commit -m blah, git push commands.
  5. Fix what is needed to be fixed.
  6. commit, push again.

It will surely okay, although you will have an intermediate state where the merge is already applied, but the code isn't working. On my opinion, it is not a problem - at least, not on a development branch. If you need to do everything in a single, unified commit, you can play with cherry-pick and rebase (first I like much better, but others like rebase).

If you did rebase as well, it can make things much more problematic, although it is matter of opinion (I am highly against rebase, but others have different opinion).

Upvotes: 1

Related Questions