0

In my README.md I have a link to a GitHub issue:

Fix world
__ Fix: https://github.com/eth-brownie/brownie/issues/1174

I am continually rewriting (and then force pushing) a commit to GitHub. (message contains the last commit's message which contains the GitHub issue link):

message=$(git log -1 --pretty=%B | awk 'NF{$1=$1};!NF||!seen[$0]++')
git commit --amend --quiet --no-verify -m "$message"
git push -f

After doing this operation many times, in the GitHub issue link I see the following: enter image description here

Overall I observe that each commit into my last commit had a footprint into the GitHub issue URL. Would it be possible to prevent this?

Basically after doing adding more changes to the last commit, I want to clean its previous linked footprints on GitHub issues, and only keep a single reference related to my latest commit.


What's the reason to rewrite a commit so many times?

I doing my work in a development branch.

By habbit I keep doing this operation when I make a single change on the branch I am working on. When I switched into another node, I do git pull --rebase (this triggers itself automatically on the background) and I continue on working on the branch and if I make change I do the commit again into the latest commit.

I just wanted to keep my git history clean for other nodes.

alper
  • 2,919
  • 9
  • 53
  • 102
  • Presumably you _have_ pushed all of those commits with messages referencing the issue, though? This is what happens when you rewrite public history; most of those commits are now unreachable (_"This commit does not belong to any branch on this repository..."_), but they **do** all refer to the issue. It's unclear why you've needed to keep rewriting the same commit over and over again, but it looks like there's a lot in it - maybe you should make more smaller commits, rather than constantly rewriting a large one? Or don't push until it's finished. – jonrsharpe Aug 18 '21 at 07:53
  • @jonrsharpe `you have pushed all of those commits with messages referencing the issue` Yes sir, commit message remains unchange which contains the URL to the issue. I was keep pushing them into my `dev` branch which will be pull from other nodes if there will be any change. I was assuming since I am overwriting into my latest commit I thought that there will be single commit that contains all the changes I made. I just wanted to keep my commit history clean , I am not sure this way is a proper way to do it. – alper Aug 18 '21 at 10:22
  • There's only a single commit _in the branch_, but you've pushed a bunch of others that still exist _within GitHub_. A better way to keep a clean history would be to think about splitting the work up into smaller units, git becomes a lot less useful when everything you're doing is bundled into one massive change. – jonrsharpe Aug 18 '21 at 10:24
  • @jonrsharpe Ah I thought the prevously pushed commits will merge with the latest one I was pushing. Probably I am doing this operation every hour to save changes. I should work on to splitting the work up into smaller units, thanks for the advice. Should I delete this question since it has duplicated version? – alper Aug 18 '21 at 10:37
  • @AD7six yes! I am repeatedly rewriting my master branch history. This commit https://github.com/ebloc/ebloc-broker/commit/295ecfd6d643559b6fe26a326eef70930fa7ef3c contains I think 1 year of work. i may also squashed plenty commits along the way as well – alper Aug 18 '21 at 10:41
  • 2
    may I suggest: not doing that (:. It is not normal to rewrite history on a public branch; creating a PR, never amending commits added to that PR branch, and then squash-merging the PR (when you are satisfied the PR is complete) is one example of a standard workflow with the same result. I recommend looking for info on how software is released, [gitflow](https://nvie.com/posts/a-successful-git-branching-model/) is one commonly-cited example. – AD7six Aug 18 '21 at 11:00
  • @AD7six I am the only one who works in repo, I didn't give much attention I was just pushing all into single commit ah :) Thank you for your advice `how software is released` should be teach in schools, which I am have lack of experience. I just wanted to keep my repo updated. For example I am working in multiple nodes and all are using same personal configuration git repo. I am keep overwriting into latest commit hoping to keep up to date for all. – alper Aug 18 '21 at 11:13
  • Please note that when contacting with GitHub contact staff to force to run garbage collector it clears dangling commits. Currently duplicated answer was actually removing comments from PRs, mine was removing commits. For clearity please see actual related answer: https://stackoverflow.com/questions/34582480/remove-commit-for-good/34594815#34594815 – alper Sep 04 '21 at 20:51

0 Answers0