Questions tagged [commit]

Questions about committing a transaction or "unit of work" to a database, application or version control system.

The usual context of this tag is application and/or database transactions but it is also applicable to version control software.

Within the application/database context, a commit means that all state changes made during the current transaction are made permanent.

Within the context of version control software, the "unit of work" being committed is the total change being written to the central store. Usually, "commit" refers to the command used to perform this action (e.g., git commit or svn commit).

The nature of different source control systems lead to different styles of committing. However, there are generally two agreed upon practices:

  1. Commit only single units of work (fixing a single bug, adding a single feature, etc.) - this makes history easier to walk through. Conversely, avoid making large, sweeping commits, which pollute history.

  2. Commit messages should be fairly concise and clear. This makes understanding who has done what (typically done using a command like blame) easier. This practice is an extension of the first, because single units of work are easier to write clear commit messages for.

Beyond these two guidelines, the majority of workflow is determined by how distributed a version control system is. Generally speaking, what goes into a centralized system like Subversion is much more strictly controlled because it is harder to undo; most commits in a centralized system involve running a project's entire test suite.

Distributed systems like Git tend to be less strict about what is committed, because it is the author who chooses when to push commits to a remote repository and can run test suites before choosing to push their changes; also, any mistakes can be reversed by editing private history.

3350 questions
1864
votes
13 answers

How to undo "git commit --amend" done instead of "git commit"

I accidentally amended my previous commit. The commit should have been separate to keep history of the changes I made to a particular file. Is there a way to undo that last commit? If I do something like git reset --hard HEAD^, the first commit also…
Jesper Rønn-Jensen
  • 106,591
  • 44
  • 118
  • 155
1580
votes
18 answers

How can I revert multiple Git commits?

I have a Git repository that looks like this: A <- B <- C <- D <- HEAD I want the head of the branch to point to A, i.e., I want B, C, D, and HEAD to disappear and I want head to be synonymous with A. It sounds like I can either try to rebase…
Bill
  • 44,502
  • 24
  • 122
  • 213
1515
votes
20 answers

Changing git commit message after push (given that no one pulled from remote)

I have made a git commit and subsequent push. I would like to change the commit message. If I understand correctly, this is not advisable because someone might have pulled from the remote repository before I make such changes. What if I know that no…
K_U
  • 15,832
  • 8
  • 26
  • 29
1098
votes
17 answers

How to list all commits that changed a specific file?

Is there a way to list all commits that changed a specific file?
Daniel
  • 11,315
  • 4
  • 19
  • 15
1085
votes
30 answers

How can one change the timestamp of an old commit in Git?

The answers to How to modify existing, unpushed commits? describe a way to amend previous commit messages that haven't yet been pushed upstream. The new messages inherit the timestamps of the original commits. This seems logical, but is there a…
Dhskjlkakdh
  • 11,341
  • 5
  • 22
  • 17
1056
votes
7 answers

How can I push a specific commit to a remote, and not previous commits?

I have made several commits on different files, but so far I would like to push to my remote repository only a specific commit. Is that possible?
Robert23
  • 10,561
  • 3
  • 16
  • 3
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
878
votes
9 answers

git add only modified changes and ignore untracked files

I ran "git status" and listed below are some files that were modified/or under the heading "changes not staged for commit". It also listed some untracked files that I want to ignore (I have a ".gitignore" file in these directories). I want to put…
Steve
  • 11,831
  • 14
  • 51
  • 63
854
votes
3 answers

How to commit my current changes to a different branch in Git

Sometimes it happens that I make some changes in my working directory, and I realize that these changes should be committed in a branch different to the current one. This usually happens when I want to try out new things or do some testing and I…
Auron
  • 13,626
  • 15
  • 47
  • 54
732
votes
1 answer

How do I create a new Git branch from an old commit?

Possible Duplicate / a more recent/less clear question Branch from a previous commit using Git I have a Git branch called jzbranch and have an old commit id: a9c146a09505837ec03b. How do I create a new branch, justin, from the information listed…
JZ.
  • 21,147
  • 32
  • 115
  • 192
676
votes
5 answers

How can I reference a commit in an issue comment on GitHub?

I find a lot of answers on how to reference a GitHub issue in a git comment (using the #xxx notation). I'd like to reference a commit in my comment, generating a link to the commit details page?
LodeRunner
  • 7,975
  • 3
  • 22
  • 24
594
votes
11 answers

How to edit log message already committed in Subversion?

Is there a way to edit the log message of a certain revision in Subversion? I accidentally wrote the wrong filename in my commit message which could be confusing later. I've seen How do I edit an incorrect commit message in Git?, but the solution to…
Paige Ruten
  • 172,675
  • 36
  • 177
  • 197
487
votes
14 answers

How can I view prior commits with git blame?

Is it possible to see who edited a specific line before the commit reported by git blame, like a history of commits for a given line? For example, I run the following (on the superb uncrustify project): $ git blame -L10,+1 src/options.cpp ^fe25b6d…
Aidan Steele
  • 10,999
  • 6
  • 38
  • 59
456
votes
16 answers

Remove specific commit

I was working with a friend on a project, and he edited a bunch of files that shouldn't have been edited. Somehow I merged his work into mine, either when I pulled it, or when I tried to just pick the specific files out that I wanted. I've been…
Joshua Cheek
  • 30,436
  • 16
  • 74
  • 83
447
votes
1 answer

Git number of commits per author on all branches

I'd like to get the number of commits per author on all branches. I see that git shortlog -s -n Prints a very nice list but it is not counting the commits that are not yet merged from other branches. If iterate this command over every branch then…
jabal
  • 11,987
  • 12
  • 51
  • 99
1
2 3
99 100