Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pull for all files except one?

Tags:

git

git-pull

I want to pull changes except for one file (GNUmakefile below). I've looked at the git-pull(3) man pages, but the option is not readily apprent to me.

How do I pull all changes, but skip the file that's causing git trouble? Is there an option to "ignore files with conflicts" or "ignore file X" or similar?

(The worst part is, the GNUmakefile was copied/pasted between virtual machines, so they are nearly the same file. cryptopp-rw's makefile has a few dependency recipes added at the end of it).

cryptopp-rw$ git pull
remote: Counting objects: 7, done.
remote: Total 7 (delta 4), reused 4 (delta 4), pack-reused 3
Unpacking objects: 100% (7/7), done.
From https://github.com/weidai11/cryptopp
   4206b4a..cf08f3e  master     -> origin/master
Updating 4206b4a..cf08f3e
error: Your local changes to the following files would be overwritten by merge:
    GNUmakefile
Please, commit your changes or stash them before you can merge.
Aborting
like image 404
jww Avatar asked Jun 25 '15 22:06

jww


People also ask

How do I exclude files from git add?

Set “–assume-unchanged” to a path to exclude to check on git commit and it will exclude your file from git commit. You will need to use the git update-index and –assume-unchanged to exclude files from git commit.

Can I pull only one file from git?

Short Answergit checkout origin/master -- path/to/file // git checkout <local repo name (default is origin)>/<branch name> -- path/to/file will checkout the particular file from the downloaded changes (origin/master).

How do I pull everything from git?

To get all the changes from all the branches, use git fetch --all . And if you'd like to clean up some of the branches that no longer exist in the remote repository, git fetch --all --prune will do the cleaning up!


1 Answers

You can stash the current working tree then make a pull, this way will prevent git to throw an error and abort the process. After the pull you can restore the stashed files with:

git stash pop stash@{<revision>}

Or if this solution needs some extra steps which you want to prevent you can ignore the files which causing troubles by overriding with the files already on git repository:

git checkout HEAD^ file/to/overwrite
git pull

Or you can try to pull with -f command:

git pull -f
like image 110
Endre Simo Avatar answered Sep 28 '22 17:09

Endre Simo