git checkout: untracked working tree files would be overwritten by checkout
I have the following branches:
master, css-merge-2016, php-merge-2016
and b4-selector-removal
I was working on my local files and was committing to branch css-merge-2016
without any issue. But a couple of days back I had to checkout
to a specific commit by starting the new branch b4-selector-removal
.
After doing the above I switched to master
branch, did a git pull
. Now whenever I am checking out to the php-merge-2016
using git checkout php-merge-2016
, git status -u
shows me a list of files as untracked although I committed them from branch css-merge-2016
.
And if I want to checkout to css-merge-2016
from php-merge-2016
a long list of files with the following statement:
The following untracked working tree files would be overwritten by checkout. Please move or remove them before you can switch branches. Aborting
If I do git checkout -f php-merge-2016
it lets me switch to that branch but again if I run git status -u
all those red lines come up and said to be untracked.
css-merge-2016
and php-merge-2016
are meant for different purposes as their names suggest. And all the untracked files listed were created/worked on when I was working and committing to css-merge-2016
branch.
So if I use git add
for those untracked files while on php-merge-2016
that may not hamper anything but if I do not add them can this cause any problem as far as git is concerned? On the other hand if I go ahead and git add
those untracked files while on php-merge-2016
is this a good practice not to commit them. The problem is I will start working and commit to this branch. So if I add them won't git
ask me to commit those files?
I am sorry if my question is not very clear. Please let me know if I should add more information.
I am worried of losing my works. How can I get rid of this situation keeping everything intact? Please help!
UPDATE:
These are the steps:
git checkout -b b4-selector-removal f990b78
to checkout into a new branch from specific revision (of css-merge-2016
branch)
git reset --hard
Output: HEAD is now at bf25410 Merge branch 'master' of https://github.com/abcd/site.main.drupal
git checkout master
Switched to branch 'master' Your branch is ahead of 'origin/master' by 4 commits.
(use "git push" to publish your local commits)
subrara@subrara-desktop:/var/www/devsite.com/dev.main.drupal$ git status On branch master
Your branch is ahead of 'origin/master' by 4 commits.
(use "git push" to publish your local commits)
Untracked files: (use "git add ..." to include in what will be committed)
sites/all/themes/base/sass/all/desktop/
sites/all/themes/base/sass/all/mobile/
sites/all/themes/base/sass/all/pages/
sites/all/themes/base/sass/all/print/
sites/all/themes/base/sass/all/sidebar/
But i don't want to push track / push these files to master yet so I did not take any action rather went for a fresh pull.
git pull
Already up-to-date.
Next two commands created and pushed the new branch from master: git checkout -b php-merge-2016 git push -u origin php-merge-2016
Before checking out to the new branch I first did a git reset --hard
HEAD is now at bf25410 Merge branch 'master' of https://github.com/abcd/site.main.drupal
git checkout php-merge-2016
Switched to branch 'php-merge-2016'
While on this branch I ran git status
which gave me the following (the folders only):
Untracked files:
(use "git add ..." to include in what will be committed)
sites/all/themes/base/sass/all/desktop/
sites/all/themes/base/sass/all/mobile/
sites/all/themes/base/sass/all/pages/
sites/all/themes/base/sass/all/print/
sites/all/themes/base/sass/all/sidebar/
nothing added to commit but untracked files present (use "git add" to track)
and then git status -u
gives me individual files under each of the above folder:
On branch php-merge-2016 Untracked files:
(use "git add ..." to include in what will be committed)
sites/all/themes/base/sass/all/desktop/_article_block.scss
sites/all/themes/base/sass/all/desktop/_columns_sidebar_left_right.scss
sites/all/themes/base/sass/all/mobile/_block_winner_email_signup.scss
sites/all/themes/base/sass/all/mobile/_header.scss
sites/all/themes/base/sass/all/pages/_blog.scss
sites/all/themes/base/sass/all/pages/_branded_name_display.scss
sites/all/themes/base/sass/all/pages/_catalog.scss
sites/all/themes/base/sass/all/print/_general.scss sites/all/themes/base/sass/all/print/_print.scss sites/all/themes/base/sass/all/sidebar/_flyout.scss sites/all/themes/base/sass/all/sidebar/_get_local_info.scss sites/all/themes/base/sass/all/sidebar/_weather_widget.scss
nothing added to commit but untracked files present (use "git add" to track)
上一篇: 从Git历史记录中删除敏感文件及其提交