Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Jul 112013

Rewriting last Git commit


Sometimes, when you regret your last commit and before it is pushed to remote, it is easy with the following commands:

git add file1.txt file2.txt
git commit -m 'Add some files'

# Now you regret to include file2.txt
git rm file2.txt
git commit --amend # Edit the commit message in the editor
Jan 122013

How to merge a specific file from another branch in Git


You have two branches, develop and master. The develop branch contains a lot of commits but you only want to merge a particular commit (of two files), what would you do?

You can use git cherry-pick but the easiest way to do and most people need is the following:

# git checkout master
# git checkout develop /path/to/file1
# git checkout develop /path/to/file2
git commit -m 'Merge changes from develop for file1 and file2'