3,375 questions
4499
votes
42
answers
5.7m
views
How do I delete a commit from a branch?
How do I delete a commit from my branch history? Should I use git reset --hard HEAD?
2729
votes
23
answers
1.5m
views
How to branch from a previous commit
If I have an n number of commits, how can I create a branch from the n-3 commit?
2042
votes
14
answers
795k
views
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 ...
1775
votes
19
answers
1.4m
views
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 ...
1756
votes
21
answers
1.4m
views
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 ...
1244
votes
33
answers
736k
views
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 ...
1217
votes
18
answers
497k
views
How to list all commits that changed a specific file?
Is there a way to list all commits that changed a specific file?
1140
votes
7
answers
892k
views
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?
1030
votes
8
answers
420k
views
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?
943
votes
10
answers
632k
views
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 "....
889
votes
3
answers
597k
views
How to commit my current changes to a different branch in Git [duplicate]
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 ...
786
votes
1
answer
504k
views
How do I create a new Git branch from an old commit? [duplicate]
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 ...
723
votes
5
answers
375k
views
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?
602
votes
12
answers
331k
views
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 ...
523
votes
14
answers
162k
views
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 ...
511
votes
4
answers
419k
views
Find a commit on GitHub given the commit hash
I am fairly new to Github and have come across an amateur-ish problem.
I have been asked to do a code review and have been provided with a commit hash, however I have tried looking in Git if I can ...
507
votes
17
answers
879k
views
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 ...
489
votes
21
answers
336k
views
GitHub pull request showing commits that are already in target branch
I'm trying to review a pull request on GitHub to a branch that isn't master. The target branch was behind master and the pull request showed commits from master, so I merged master and pushed it to ...
483
votes
2
answers
183k
views
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. ...
447
votes
5
answers
266k
views
How to move certain commits to be based on another branch in git?
The situation:
master is at X
quickfix1 is at X + 2 commits
Such that:
o-o-X (master HEAD)
\
q1a--q1b (quickfix1 HEAD)
Then I started working on quickfix2, but by accident took quickfix1 ...
422
votes
10
answers
103k
views
Start a Git commit message with a hashmark (#)
Git treats lines starting with # (hash, number sign, octothorpe, pound sign) as comment lines when committing. This is very annoying when working with a ticket tracking system, and trying to write the ...
356
votes
22
answers
444k
views
Git error on commit after merge - fatal: cannot do a partial commit during a merge
I ran a git pull that ended in a conflict. I resolved the conflict and everything is fine now (I used mergetool also).
When I commit the resolved file with git commit file.php -m "message" I get the ...
349
votes
3
answers
161k
views
Temporarily switch working copy to a specific Git commit
How to switch to specific Git commit without losing all the commits made after it?
I want that local files will be changed, but commits' database will remain intact, only the current position pointer ...
339
votes
5
answers
91k
views
How can I find the commit in which a given file was added?
Say I have a file foo.js that was committed some time ago. I would like to simply find the commit where this file was first added.
After reading the answers and my own tinkering, this works for me:
...
334
votes
3
answers
626k
views
git revert back to certain commit [duplicate]
how do i revert all my files on my local copy back to a certain commit?
commit 4a155e5b3b4548f5f8139b5210b9bb477fa549de
Author: John Doe <[email protected]>
Date: Thu Jul 21 20:51:38 2011 ...
321
votes
11
answers
182k
views
How to remove the first commit in git?
I am curious about how to remove the first commit in git.
What is the revision before committing any thing? Does this revision have a name or tag?
304
votes
4
answers
176k
views
Install specific git commit with pip
I'm developing a django app and I'm using pip to manage my requirements. How can I do to install a specific git's commit?
In my case I need to install this commit:
https://github.com/aladagemre/...
304
votes
6
answers
56k
views
How can I split up a Git commit buried in history?
I flubbed up my history and want to do some changes to it. Problem is, I have a commit with two unrelated changes, and this commit is surrounded by some other changes in my local (non-pushed) history.
...
299
votes
3
answers
197k
views
How do you move a commit to the staging area in git?
If you want to move a commit to the staging area - that is uncommit it and move all of the changes which were in it into the staging area (effectively putting the branch in the state that it would ...
285
votes
21
answers
715k
views
Error "Updates were rejected because the remote contains work that you do not have locally"
I'm working on a team with a few developers using Git on Bitbucket. We are all working on a dev branch, not pushing to master until a release.
One of the developers committed incorrect code that ...
275
votes
4
answers
617k
views
Merging 2 branches together in Git
I've only just started to use Git and think it is wonderful, however I'm a little confused over what the merge command does.
Let us say we have a working project in the branch "A".
I go home ...
269
votes
6
answers
250k
views
How can I delete the last n commits on GitHub and locally?
I'm trying to delete the last two commits from one of my GitHub repositories. I've tried as suggested here: git push -f origin HEAD^^:master. It seems that it works, as the last two commits are ...
265
votes
5
answers
171k
views
How to commit no change and new message?
How can I make a new commit and create a new message if no changes are made to files?
Is this not possible since the commit's code (SHA ?) will be the same?
250
votes
9
answers
225k
views
How to remove selected commit log entries from a Git repository while keeping their changes?
I would like to remove selected commit log entries from a linear commit tree, so that the entries do not show in the commit log.
My commit tree looks something like:
R--A--B--C--D--E--HEAD
I would ...
244
votes
9
answers
262k
views
Editing the git commit message in GitHub
Is there any way of online editing the commit message in GitHub.com, after submission?
From the command line, one can do
git commit --amend -m "New commit message"
as correctly suggested in ...
238
votes
10
answers
90k
views
See "real" commit date / time in github (hour/day)
Is there a way to see the date of a commit in github, with day/hour precision? Older commits appear in a "human readable" format, such as "2 years ago" instead of showing the actual date.
If it's not ...
236
votes
6
answers
241k
views
Git commit in terminal opens VIM, but can't get back to terminal
Trying to learn GitHub at the moment and doing this Git essentials tutorial over at nettuts. I'm on the lesson about making commits.
The teacher types git commit and it opens VIM as his editor (I'd ...
228
votes
8
answers
145k
views
Git: How to edit/reword a merge commit's message?
How do I edit or reword a merge commit's message?
git commit --amend works if it's the last commit made (HEAD), but what if it comes before HEAD?
git rebase -i HEAD~5 doesn't list the merge commits.
227
votes
8
answers
118k
views
Mercurial: how to amend the last commit?
I'm looking for a counter-part of git commit --amend in Mercurial, i.e. a way to modify the commit which my working copy is linked to. I'm only interested in the last commit, not an arbitrary earlier ...
218
votes
2
answers
138k
views
How to find commits by a specific user in Git? [duplicate]
Our project uses Git as the version control system and recently I needed to review someone's commits. How can I see a list of commits made by a specific user?
209
votes
14
answers
550k
views
How to add multiple files to Git at the same time
This will be my first git use. I have added new files ( a lot ) to the folder/project ( git local repository).
I went through online tutorials and forums and see i can do
git commit -a
So I go to the ...
188
votes
8
answers
223k
views
Combining Multiple Commits Into One Prior To Push
This question pertains not only to how to accomplish this task, but to whether doing so is good or bad practice with Git.
Consider that locally I do most work on the main branch, but I have created a ...
186
votes
8
answers
148k
views
How to git ignore ipython notebook checkpoints anywhere in repository
This is mostly a git question. I want to commit my ipython notebooks but gitignore the checkpoints.
The repo has multiple folders which each have ipython notebooks, therefore just ignoring a single ...
174
votes
10
answers
229k
views
GIT commit as different user without email / or only email
I'm trying to commit some changes as a different user, but i do not have a valid email address, following command is not working for me:
git commit --author="john doe" -m "some fix"
fatal: No ...
171
votes
7
answers
536k
views
git - Your branch is ahead of 'origin/master' by 1 commit
I am newbie in git and I am working on git.
I added some files in git :
git add <file1>
git add <file2>
then I wanted to push that for review, but mistakenly I did
git commit
so the ...
169
votes
10
answers
249k
views
Git commit with no commit message
How can I commit changes without specifying commit message? Why is it required by default?
164
votes
9
answers
181k
views
Git: add vs push vs commit
What is the difference between git add, push and commit?
Just a little confused coming from SVN, where "update" will 'add' stuff, and commit does a "push" and will 'add' as well
There are all ...
158
votes
3
answers
96k
views
How do you commit code as a different user?
I want to be able to do this for a script. I'm essentially re-creating the entire version history of some code in Git - it currently uses a different version control system. I need the script to be ...
155
votes
5
answers
163k
views
Problems with entering Git commit message with Vim
OS: Windows
I write
$ git commit
then
"# Please enter the commit message"
I write some text, like
"Form validation added"
Press Enter and not commited. Then i press Shift+Enter, Ctrl+Enter, Alt+...
150
votes
10
answers
208k
views
What happens if you don't commit a transaction to a database (say, SQL Server)?
Suppose I have a query:
begin tran
-- some other sql code
And then I forget to commit or roll back.
If another client tries to execute a query, what would happen?