Questions tagged [git-commit]

git-commit - Record changes to the repository along with a log message.

Stores the current contents of the index in a new commit along with a log message from the user describing the changes.

Added from reference

2117 questions
953
votes
8 answers

How to amend a commit without changing commit message (reusing the previous one)?

Is there a way to amend a commit without vi (or your $EDITOR) popping up with the option to modify your commit message, but simply reusing the previous message?
Sridhar Sarnobat
  • 25,183
  • 12
  • 93
  • 106
943
votes
8 answers

Link to the issue number on GitHub within a commit message

Is it somehow possible to automatically have a link to GitHub issue number in the git commit message?
Mika Tuupola
  • 19,877
  • 5
  • 42
  • 49
906
votes
8 answers

How to cancel a local git commit?

My issue is I have changed a file e.g.: README, added a new line 'this for my testing line' and saved the file, then I issued the following commands: git status # On branch master # Changed but not updated: # (use "git add ..." to update…
Amal Kumar S
  • 15,555
  • 19
  • 56
  • 88
876
votes
18 answers

Make the current commit the only (initial) commit in a Git repository?

I currently have a local Git repository, which I push to a Github repository. The local repository has ~10 commits, and the Github repository is a synchronised duplicate of this. What I'd like to do is remove ALL the version history from the local…
kaese
  • 10,249
  • 8
  • 29
  • 35
838
votes
21 answers

How do I push amended commit to the remote Git repository?

When I've worked a bit with my source code, I did my usual thing commit and then I pushed to a remote repository. But then I noticed I forgot to organize my imports in the source code. So I do the amend command to replace the previous commit: > git…
Spoike
  • 119,724
  • 44
  • 140
  • 158
830
votes
9 answers

Please enter a commit message to explain why this merge is necessary, especially if it merges an updated upstream into a topic branch

I am using Git. I did a pull from a remote repo and got an error message: Please enter a commit message to explain why this merge is necessary, especially if it merges an updated upstream into a topic branch. I try to type a message and press…
bernie2436
  • 22,841
  • 49
  • 151
  • 244
798
votes
14 answers

How to fix committing to the wrong Git branch?

I just made a perfectly good commit to the wrong branch. How do I undo the last commit in my master branch and then take those same changes and get them into my upgrade branch?
mikewilliamson
  • 24,303
  • 17
  • 59
  • 90
716
votes
4 answers

What is the Sign Off feature in Git for?

What's the point of the Sign Off feature in Git? git commit --signoff When should I use it, if at all?
Clark Gaebel
  • 17,280
  • 20
  • 66
  • 93
682
votes
7 answers

Should I use past or present tense in git commit messages?

I read once that git commit messages should be in the imperative present tense, e.g. "Add tests for x". I always find myself using the past tense, e.g. "Added tests for x" though, which feels a lot more natural to me. Here's a recent John Resig…
Skilldrick
  • 69,215
  • 34
  • 177
  • 229
576
votes
16 answers

Fix GitLab error: "you are not allowed to push code to protected branches on this project"?

I have a problem when I push my code to git while I have developer access in my project, but everything is okay when I have master access. Where is the problem come from? And how to fix it? Error message: error: You are not allowed to push code to…
541
votes
7 answers

Pushing empty commits to remote

I have pushed one commit to remote but now I realized that the commit message is not correct. I would like to change the commit message but AFAIK it is not possible. So i decided to create empty commit with correct message: git commit…
mrutyunjay
  • 6,850
  • 7
  • 25
  • 35
506
votes
12 answers

Remove sensitive files and their commits from Git history

I would like to put a Git project on GitHub but it contains certain files with sensitive data (usernames and passwords, like /config/deploy.rb for capistrano). I know I can add these filenames to .gitignore, but this would not remove their history…
Stefan
  • 9,289
  • 7
  • 38
  • 46
474
votes
21 answers

git: Your branch is ahead by X commits

How does this actually come about? I am working in one repo by myself at the moment, so this is my workflow: Change files Commit Repeat 1-2 until satisfied Push to master Then when I do a git status it tells me that my branch is ahead by X commits…
SeanJA
  • 10,234
  • 5
  • 32
  • 42
430
votes
3 answers

Reset all changes after last commit in git

How can I undo every change made to my directory after the last commit, including deleting added files, resetting modified files, and adding back deleted files?
Dogbert
  • 212,659
  • 41
  • 396
  • 397
411
votes
15 answers

How do I make a Git commit in the past?

I'm converting everything over to Git for my own personal use and I found some old versions of a file already in the repository. How do I commit it to the history in the correct order according the file's "date modified" so I have an accurate…
unknown
  • 4,129
  • 3
  • 16
  • 7