Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I force git to checkout the master branch and remove carriage returns after I've normalized files using the "text" attribute?

People also ask

How do I force checkout master in git?

Force a Checkout You can pass the -f or --force option with the git checkout command to force Git to switch branches, even if you have un-staged changes (in other words, the index of the working tree differs from HEAD ). Basically, it can be used to throw away local changes.

How do I reset a master branch to empty?

You could try to reset the master branch to the first commit with git checkout master; git reset --hard ${sha-of-first-commit} and then amend that first commit to remove the file s in it.

How do I checkout and ignore changes?

you can do git checkout -m <branch-name> to merge conflicts and checkout to the branch and resolve conflicts yourself, or git checkout -f <branch-name> to ignore changes.


Ahah! Checkout the previous commit, then checkout the master.

git checkout HEAD^
git checkout -f master

As others have pointed out one could just delete all the files in the repo and then check them out. I prefer this method and it can be done with the code below

git ls-files -z | xargs -0 rm
git checkout -- .

or one line

git ls-files -z | xargs -0 rm ; git checkout -- .

I use it all the time and haven't found any down sides yet!

For some further explanation, the -z appends a null character onto the end of each entry output by ls-files, and the -0 tells xargs to delimit the output it was receiving by those null characters.


Stash (save) your changes

git stash

Take updated changes till the last commit from remote for your current branch (to start clean with no untracked/modified files .. just in case)

git checkout .

Now switch to the master branch

git checkout master