Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create cme for empty commit #53

Closed
wants to merge 1 commit into from

Conversation

shunkakinoki
Copy link
Contributor

cme as a commit git alias for conventional empty commits

@joelparkerhenderson
Copy link
Member

Thanks for the pull request!

Can you help me understand the usage and/or purpose of this?

For example, if the purpose is to do the first commit blank, then that sounds like a good idea to me, and would be good to ensure it's solely on the first commit. An alias could perhaps be init-empty or commit-0 or commit-first etc.?

For example, if the purpose is to do an empty commit to artificially invoke a workflow, such as triggering a hook or process, then that sounds like a good idea to me /if/ the alias guarantees the commit is empty. An alias could perhaps be commit-empty or cem meaning commit empty --message etc.?

Is there a usage and/or purpose where the user wouldn't know and/or wouldn't care if the commit was empty or not?

@phdru
Copy link
Contributor

phdru commented Jun 5, 2019

For example, if the purpose is to do an empty commit to artificially invoke a workflow, such as triggering a hook or process, then that sounds like a good idea to me /if/ the alias guarantees the commit is empty.

I support this excelent approach! Overall I'm +0 about the PR.

@shunkakinoki
Copy link
Contributor Author

shunkakinoki commented Jun 7, 2019

Thank you guys, really appreciate the feedback.

To explain the purpose of the PR,
(Take in mind that it may be more of a Japanese style approach)

Often when you want to edit a commit towards the beginning(that contains actual changes),
you will have to

git rebase -i --root
git update-ref -d

git commit --allow-empty --message
allows you to
rebase and commit --ammend
rather easy.

Source:
https://qiita.com/NorsteinBekkler/items/b2418cd5e14a52189d19
(Apologies for the Japanese source)

@joelparkerhenderson
Copy link
Member

joelparkerhenderson commented Jun 7, 2019

Good. Your Japanese source describes the goal of doing git init, then an empty commit.

To discover if there are any commits:

git rev-list --all --count

To do the commit only when its the first, and to use a blank message:

[ $(git rev-list --all --count) -eq 0 ] \
&& git commit --allow-empty --message ''

To add an error message, something like this:

[ $(git rev-list --all --count) -eq 0 ] \
&& git commit --allow-empty --message ''
|| >&2 printf "error: this solely works as the first commit\n"

As far as I can tell from your blog post link, and from other posts, the commit message does not add any value because the commit is obviously the first commit, and obviously empty. So the message could/should be an empty string.

What do you all think of this so far?

An alternate way to do the same kind of goal could/would be to create an alias for init, such as:

alias init-empty 

(or init-commit, or..?)

... that does:

git init && git commit --allow-empty --message ''

@shunkakinoki
Copy link
Contributor Author

Agree!!!

alias init-empty 

sounds great to me!

@joelparkerhenderson
Copy link
Member

Good. Would you like to make the change in your branch, and push to this pull request? This will update the pull request, then I'll merge it. This helps everyone see your idea and contribution.

Or if you're short on time and don't care about the authorship, then let me know, and I can add it for you.

@shunkakinoki
Copy link
Contributor Author

@joelparkerhenderson Really Appreciate the generous feedback,
it really helps for engineering novices like me getting into coding!!!

On that note,
I personally use the empty commit often when creating new branches.
Would separating the two below be a good idea?

 init-empty = git init && git commit --allow-empty --message ''
init-branch =  commit --allow-empty --message ''

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants