For all unstaged files in current working directory use:
git checkout -- .
For a specific file use:
git checkout -- path/to/file/to/revert
--
here to remove ambiguity (this is known as argument disambiguation).
For Git 2.23 onwards, one may want to use the more specific
git restore .
resp.
git restore path/to/file/to/revert
that together with git switch
replaces the overloaded git checkout
(see here), and thus removes the argument disambiguation.
Try: git mergetool
It opens a GUI that steps you through each conflict, and you get to choose how to merge. Sometimes it requires a bit of hand editing afterwards, but usually it's enough by itself. It is much better than doing the whole thing by hand certainly.
As per Josh Glover's comment:
The command
doesn't necessarily open a GUI unless you install one. Running git mergetool
for me resulted in vimdiff
being used. You can install
one of the following tools to use it instead: meld
, opendiff
,
kdiff3
, tkdiff
, xxdiff
, tortoisemerge
, gvimdiff
, diffuse
,
ecmerge
, p4merge
, araxis
, vimdiff
, emerge
.
Below is the sample procedure to use vimdiff
for resolve merge conflicts. Based on this link
Step 1: Run following commands in your terminal
git config merge.tool vimdiff
git config merge.conflictstyle diff3
git config mergetool.prompt false
This will set vimdiff as the default merge tool.
Step 2: Run following command in terminal
git mergetool
Step 3: You will see a vimdiff display in following format
╔═══════╦══════╦════════╗
║ ║ ║ ║
║ LOCAL ║ BASE ║ REMOTE ║
║ ║ ║ ║
╠═══════╩══════╩════════╣
║ ║
║ MERGED ║
║ ║
╚═══════════════════════╝
These 4 views are
LOCAL – this is file from the current branch
BASE – common ancestor, how file looked before both changes
REMOTE – file you are merging into your branch
MERGED – merge result, this is what gets saved in the repo
You can navigate among these views using ctrl+w. You can directly reach MERGED view using ctrl+w followed by j.
More information about vimdiff navigation is here and here.
Step 4. You could edit the MERGED view the following way
If you want to get changes from REMOTE
:diffg RE
If you want to get changes from BASE
:diffg BA
If you want to get changes from LOCAL
:diffg LO
Step 5. Save, Exit, Commit and Clean up
:wqa
save and exit from vi
git commit -m "message"
git clean
Remove extra files (e.g. *.orig) created by diff tool.
Best Answer
Create a users file (i.e.
users.txt
) for mapping SVN users to Git:You can use this one-liner to build a template from your existing SVN repository:
SVN will stop if it finds a missing SVN user, not in the file. But after that, you can update the file and pick up where you left off.
Now pull the SVN data from the repository:
This command will create a new Git repository in
dest_dir-tmp
and start pulling the SVN repository. Note that the "--stdlayout" flag implies you have the common "trunk/, branches/, tags/" SVN layout. If your layout differs, become familiar with--tags
,--branches
,--trunk
options (in generalgit svn help
).All common protocols are allowed:
svn://
,http://
,https://
. The URL should target the base repository, something like http://svn.mycompany.com/myrepo/repository. The URL string must not include/trunk
,/tag
or/branches
.Note that after executing this command it very often looks like the operation is "hanging/frozen", and it's quite normal that it can be stuck for a long time after initializing the new repository. Eventually, you will then see log messages which indicate that it's migrating.
Also note that if you omit the
--no-metadata
flag, Git will append information about the corresponding SVN revision to the commit message (i.e.git-svn-id: svn://svn.mycompany.com/myrepo/<branchname/trunk>@<RevisionNumber> <Repository UUID>
)If a user name is not found, update your
users.txt
file then:You might have to repeat that last command several times, if you have a large project until all of the Subversion commits have been fetched:
When completed, Git will checkout the SVN
trunk
into a new branch. Any other branches are set up as remotes. You can view the other SVN branches with:If you want to keep other remote branches in your repository, you want to create a local branch for each one manually. (Skip trunk/master.) If you don't do this, the branches won't get cloned in the final step.
Tags are imported as branches. You have to create a local branch, make a tag and delete the branch to have them as tags in Git. To do it with tag "v1":
Clone your GIT-SVN repository into a clean Git repository:
The local branches that you created earlier from remote branches will only have been copied as remote branches into the newly cloned repository. (Skip trunk/master.) For each branch you want to keep:
Finally, remove the remote from your clean Git repository that points to the now-deleted temporary repository: