0

On my branch I've got 3 commits. Commits A and B were done from command line, commit C directly from github. How can I amend the message of commit C? I cannot do that directly on github but for some reason I cannot see commit C in history when running git log (I got only A and B in the results). Also running git rebase -i origin/master lets me ammend only commits A and B. I run git pull after adding commit C but that didn't do the trick. What's the proper way to do that?

Malvinka
  • 1,185
  • 1
  • 15
  • 36
  • Possible duplicate of [How to modify existing, unpushed commits?](https://stackoverflow.com/questions/179123/how-to-modify-existing-unpushed-commits) – Makoto Sep 12 '18 at 19:50
  • @Makoto that's totally different case. My commit I want to amend was not made locally. – Malvinka Sep 12 '18 at 19:53
  • I disagree. Amending commits is a fairly well-defined process and the answerse you're going to receive aren't going to diverge from what's in the dupe. – Makoto Sep 12 '18 at 20:25
  • *Commits A and B were done from command line, commit C directly from github.* How did you create command C? That is, did you click on a "merge pull request" button, or what? (Not directly relevant to answer, but useful for knowing what you were doing in general.) – torek Sep 12 '18 at 21:01
  • @torek, when you view the file on github you have the "edit" button that let you make changes and then, below, you can either add it as a commit to the current branch or create new branch. – Malvinka Sep 13 '18 at 07:59

2 Answers2

2

I'm gonna assume you know what you're doing and want to intentionally amend the commit from the remote, which in practice is gonna be a destructive operation (delete the old, add the new and generate missing refs to anyone working based on that commit). That said, it's pretty straightforward.

Pull their change with the problematic commit:

git pull

Apply your fix and amend it locally:

git add .
git commit --amend

Force push to your remote

git push -f

Let everyone who works under this repo that you did that so they can fix their missing refs.

everton
  • 7,579
  • 2
  • 29
  • 42
1

Just fetch on your local, git checkout the remote branch, git commit --amend, git push -f origin HEAD:remote-branch-name. That should be enough

eftshift0
  • 26,375
  • 3
  • 36
  • 60
  • what's the difference between `git pull` and `git checkout`? Looks like that's where I am lost. – Malvinka Sep 12 '18 at 20:10
  • And no, unfortunately after checkout still my git history doesn't see that commit made on github :/ – Malvinka Sep 12 '18 at 20:11
  • actually, they are quite different. `git pull` is more or less `git fetch` followed by `git merge`. It merges the branch that the branch you checked out is tracking (my guess, I'm not fond of pull because it does 2 things when I normally want to control step by step.... me, a control freak, I guess). `git checkout` is, well... start working somewhere else. – eftshift0 Sep 12 '18 at 20:11
  • 1
    And fetch runs fine? And the revision you are trying to amend is the tip of a remote branch on that repo? And you don't get that remote branch updated when fetching? – eftshift0 Sep 12 '18 at 20:13